Note that there are some explanatory texts on larger screens.

plurals
  1. POpreg_match, addslashes,mb_substr not working for long strings
    primarykey
    data
    text
    <p>I am parsing an html file. I have a big string which is basically a script. The string looks likes this:</p> <blockquote> <p>var spConfig = new Product.Config({"outofstock":["12663"],"instock":["12654","12655","12656","12657","12658","12659","12660","12661","12662","12664","12665"],"attributes":{"698":{"id":"698","code":"aubade_import_colorcode","label":"Colorcode","options":[{"id":"650","label":"BLUSH","price":"0","products":["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","label":"85","price":"0","products":["12654","12657","12660","12663"]},{"id":"450","label":"90","price":"0","products":["12655","12658","12661","12664"]},{"id":"451","label":"95","price":"0","products":["12656","12659","12662","12665"]}]},"702":{"id":"702","code":"aubade_import_size_cup","label":"Size Cup","options":[{"id":"1501","label":"A","price":"0","products":["12654","12655","12656"]},{"id":"1502","label":"B","price":"0","products":["12657","12658","12659"]},{"id":"1503","label":"C","price":"0","products":["12660","12661","12662"]},{"id":"1504","label":"D","price":"0","products":["12663","12664","12665"]}]}},"template":"\u20ac#{price}","basePrice":"57","oldPrice":"57","productId":"12666","chooseText":"Choose option...","taxConfig":{"includeTax":true,"showIncludeTax":true,"showBothPrices":false,"defaultTax":19.6,"currentTax":19.6,"inclTaxTitle":"Incl. Tax"}}); var colorarray = new Array();</p> <pre><code> 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'; // // </code></pre> <p>Event.observe(window, 'load', function() { //<br> setImages('attribute698', null, currentColorLabel); // });</p> </blockquote> <p>I need to extract the content from first "(" upto first ";". I have tried to do string extract and failed.I have tried preg match I have failed. Kindly tell me some solution to my problem.Below are my tried solution and issues.</p> <pre><code>$strScript = $tagscript-&gt;item(0)-&gt;nodeValue; //this line returns empty string $str_slashed = addslashes(trim($strScript) ); $pattern = '/\((.*);/'; preg_match($pattern,$str_slashed,$matches); echo 'matches'."&lt;br /&gt;"; var_dump($matches); //Add slashes works only if I use it before assignment to other string $matches = array(); $strScript = addslashes ($tagscript-&gt;item(0)-&gt;nodeValue);//. "&lt;br /&gt;"; $pattern = '/\((.*);/'; preg_match($pattern,$strScript,$matches); echo 'matches'."&lt;br /&gt;"; var_dump($matches); //str extract method $posBracket = stripos ($strScript,'('); echo $posBracket."&lt;br /&gt;"; $posSemiColon = strpos ($strScript,';'); echo $posSemiColon."&lt;br /&gt;"; $temp = mb_substr ($strScript,$posBracket ,($posSemiColon-$posBracket)); echo $temp."&lt;br /&gt;"; </code></pre> <p>The above code works for small strings </p> <pre><code>$strScript = "manisha( [is goo girl] {come(will miss u) \and \"play} ; lets go home;"; </code></pre> <p>but wont work for the long strings. How can i resolve this issue?Please help me!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload