我正在解析一个html文件。我有一个很大的字符串,基本上是一个脚本。 的字符串如下喜欢这样的:preg_match,addslashes,mb_substr不适用于长字符串
变种spConfig =新 Product.Config({ “outofstock”:[ “12663”], “的inStock”:[ “12654”, “12655”, “12656”, “12657”, “12658”, “12659”, “12660”, “12661”, “12662”, “12664”, “12665”], “属性”:{ “698”:{ “ID”: “698” “代码”: “aubade_import_colorcode”, “标签”: “的ColorCode”, “选项”:[{ “ID”: “650”, “标签”: “腮红”, “价格”: “0”, “产品” :[ “12654”, “12655”, “12656”, “12657”, “12658”, “12659”, “12660”, “12661”, “12662”, “12663”, “12664”, “12665”] }“},”689“:{”id“:”689“,”code“:”aubade_import_size_width“,”label“:”Size Width“,”options“:[{”id“:”449“标签 “:” 85" , “价格”: “0”, “产品”:[ “12654”, “12657”, “12660”, “12663”]},{ “ID”: “450”, “标签” : “90”, “价格”: “0”, “产品”:[ “12655”, “12658”, “12661”, “12664”]},{ “ID”: “451”, “标签”:” 95" , “价格”: “0”,“PR oducts “:[” 12656" , “12659”, “12662”, “12665”]}]}, “702”:{ “ID”: “702”, “代码”: “aubade_import_size_cup”, “标签”:”尺寸 Cup“,”options“:[{”id“:”1501“,”label“:”A“,”price“:”0“,”products“:[”12654“,”12655“,”12656 “]},{” ID “:” 1502" , “标签”: “B”, “价格”: “0”, “产品”:[ “12657”, “12658”, “12659”]},{” ID “:” 1503" , “标签”: “C”, “价格”: “0”, “产品”:[ “12660”, “12661”, “12662”]},{ “ID”: “1504” “标签”: “d”, “价格”: “0”, “产品”:[ “12663”, “12664”, “12665”]}]}}, “模板”:“\ u20ac#{价格} “,”basePrice“:”57“,”oldPrice“:”57“,”productId“:”12666“,”chooseText“:”选择 选项...“,”taxConfig“:{”includeTax“ “showIncludeTax”:真实的, “showBothPrices”:假的, “defaultTax”:19.6, “currentTax”:19.6, “inclTaxTitle”:“已包含。 税“}}); VAR colorarray =新的Array();
colorarray["c650"] = 'blush'; Event.observe('attribute698', 'change', function() { var colorId = $('attribute698').value; var attribute = 'attribute698'; var label = colorarray["c"+colorId]; if ($('attribute698').value != '') { setImages(attribute, colorId, label); } }); // var currentColorLabel = 'blush'; // var currentSku = '5010-4-n'; // var currentPosition = 'v'; // //
Event.observe(窗口, '负载',函数(){//
setImages( 'attribute698',NULL,currentColorLabel ); //});
我需要从第一提取内容“(”高达首先“;”。 我试图做字符串提取物和failed.I试图预浸比赛我都失败了。 请告诉我一些我的问题的解决方法。以下是我的尝试解决方案和问题。
$strScript = $tagscript->item(0)->nodeValue;
//this line returns empty string
$str_slashed = addslashes(trim($strScript));
$pattern = '/\((.*);/';
preg_match($pattern,$str_slashed,$matches);
echo 'matches'."<br />";
var_dump($matches);
//Add slashes works only if I use it before assignment to other string
$matches = array();
$strScript = addslashes ($tagscript->item(0)->nodeValue);//. "<br />";
$pattern = '/\((.*);/';
preg_match($pattern,$strScript,$matches);
echo 'matches'."<br />";
var_dump($matches);
//str extract method
$posBracket = stripos ($strScript,'(');
echo $posBracket."<br />";
$posSemiColon = strpos ($strScript,';');
echo $posSemiColon."<br />";
$temp = mb_substr ($strScript,$posBracket ,($posSemiColon-$posBracket));
echo $temp."<br />";
上面的代码适用于小弦
$strScript = "manisha([is goo girl] {come(will miss u) \and \"play} ; lets go home;";
但不会工作,为长字符串。 我该如何解决这个问题?请帮助我!
您建议的模式也不会给我结果。 –
是的,我需要json字符串来工作。这就是我str提取的全部目的。 –