Php 替换某些文本
我有以下代码:Php 替换某些文本,php,preg-replace,strpos,Php,Preg Replace,Strpos,我有以下代码: <?php $actual_link = "domain.com/search/q/laptop/attr/price_range_11_50005/attr/23914175_laptop"; if ($attribute->name == "Price range") { if (strpos($actual_link,'/attr/price_range_') !== false)
<?php
$actual_link = "domain.com/search/q/laptop/attr/price_range_11_50005/attr/23914175_laptop";
if ($attribute->name == "Price range")
{
if (strpos($actual_link,'/attr/price_range_') !== false)
{
$querystring = explode("&",preg_replace(array("/attr/price_range_[0-9_]+/", "", $actual_link)));
}
else
{
$querystring = explode("&",$actual_link);
}
}
}
您的正则表达式错误:
preg_replace(array("/attr/price_range_[0-9_]+/", "", $actual_link)
使用正斜杠/
作为分隔符时,需要对其进行转义或使用其他分隔符:
preg_replace(array("/\/attr\/price_range_[0-9_]+/", "", $actual_link)
或
嗨,如果数字之间有一个“u”有关系吗?例如价格范围11_50005@user3134976否,[0-9\]+
是字符类中1个或多个字符按任意顺序排列的序列。
preg_replace(array("#/attr/price_range_[0-9_]+#", "", $actual_link)