Answer the question
In order to leave comments, you need to log in
How to get an array from js code to php into a variable?
I have text in variable
$data = '
<script>
var isProductPage = true;
var Name = "Coll dress";
var brandName = "Dress 123";
var gender = "Womens";
</script>
Answer the question
In order to leave comments, you need to log in
$data = str_replace(array('<script>', '</script>', 'var '), '', $data);
$array_results = explode(";", $data);
if (is_array($array_results)) {
$stats_data = array();
foreach ($array_results as $key => $value) {
if (!$value) {
continue;
}
$_temp = explode(" = ", $value);
$result_data[$_temp[0]] = str_replace(';', '', $_temp[1]);
}
}
thanks, it copes well with variables, but the trouble started when parsing the array
<script>
pImgs[23] = {};
pImgs[23]['MULTIVIEW'] = {};
pImgs[23]['MULTIVIEW_THUMBNAILS'] = {};
pImgs[23]['4x'] = {};
pImgs[23]['DETAILED'] = {};
pImgs[23]['2x'] = {};
pImgs[23]['MULTIVIEW_THUMBNAILS']['p'] = '/tpm/main.jpg';
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question