PHP Regex Help preg_match -


http://regexr.com?35hk2

the above site shows correct regex when php doesn't show names such 'jj5x5's white top hat'

here php :

<?php     function newecho($value){         echo $value . "<br>";     };     function curlauto($url){         $channel = curl_init();         curl_setopt($channel, curlopt_url, $url);         curl_setopt($channel, curlopt_returntransfer, 1);         return curl_exec($channel);     };     function automatchall($string,$pattern){         $found = array();         $match = preg_match_all($pattern,$string,$found);         return $found;     };     function replacematch($string,$pattern,$subject){         return str_replace($pattern,$subject,$string);     };     $count = 0;     $output = curlauto("www.roblox.com/catalog/json?subcategory=2&sorttype=0&sortaggregation=3&sortcurrency=0&legendexpanded=true&category=2&pagenumber=1");     $assetid = automatchall($output,'/"assetid":[\d]+/');     $name = automatchall($output,'/"name":"[\w\s\d\-' . "\'" . ']+"/');     foreach($assetid[0] $value){         newecho(replacematch($value,'"assetid":',"") . ":" . replacematch(replacematch($name[0][$count],'"name":"',""),'"',""));         $count++;     };     echo $output ?> 

$name having problems regex cause showing of names when displaying running code. regex $name

/"name":"[\w\s\d\-\']+"/

but due fact cannot use ' or " string had make it

'/"name":"[\w\s\d\-' . "\'" . "]+/"

but me fix this.

my bet ' in jj5x5's white top hat "typographic apostrophe", (unicode: u+2019 "right single quotation mark", windows codepage 1252: 0x92, utf-8 in php: "\xe2\x80\x99"). tell typographic apostrophe/quote ascii single quote: if points straight down (in original string!), it's ascii single quote, if doesn't, it's typographic apostrophe/quote.

if want match closing double quotes, use '/"name":"[^"]+"/', unless can have escaped double quotes in name, in case regex becomes (in php) '/"name":"(?:[^\\\\"]|\\\\[\\\\"])+"/' (add other possible escapes last class).

btw, don't need split string of regex differently delimited strings (all have escape current delimiter), and, if do, don't need escape single quote in string delimited double quotes.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -