http://regexr.com?35hk2PHP正则表达式帮助的preg_match
上述网站显示正确的正则表达式,但是当我用PHP做它,它不显示某些名称,如'JJ5x5's White Top Hat'
这里是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] as $Value){
newEcho(replaceMatch($Value,'"AssetId":',"") . ":" . replaceMatch(replaceMatch($Name[0][$Count],'"Name":"',""),'"',""));
$Count++;
};
echo $Output
?>
$Name
是我正在使用正则表达式的问题,因为它显示运行代码时只显示一些名称。对于$Name
的正则表达式是
/"Name":"[\w\s\d\-\']+"/
但由于我不能使用“或”字符串,我不得不让
'/"Name":"[\w\s\d\-' . "\'" . "]+/"
但是你可以帮我这个。我想解决这个问题
不需要拆分字符串,你可以使用'\''。此外,'-'属于课程的开始部分(未转义)。 –
@WalterTross但是我仍然有问题,因为一些项目的名字没有显示出来!比如JJ5x5的白色礼帽 – wateraura