我有这个字符串:如何使用PHP从锚的“href”属性中删除查询字符串?
$string = '<a href="/title/tt3110958/?ref_=nm_flmg_act_2" style="color:#666" >';
如何从?
删除所有字"
在我的字符串。 我试试这个:
$result = preg_replace("/\?.+/", "", $string);
但其删除所有字?
后!
我有这个字符串:如何使用PHP从锚的“href”属性中删除查询字符串?
$string = '<a href="/title/tt3110958/?ref_=nm_flmg_act_2" style="color:#666" >';
如何从?
删除所有字"
在我的字符串。 我试试这个:
$result = preg_replace("/\?.+/", "", $string);
但其删除所有字?
后!
使用/\?[^\"]+/
像波纹管:
<?php
$string = '<a href="/title/tt3110958/?ref_=nm_flmg_act_2" style="color:#666" >';
$result = preg_replace("/\?[^\"]+/", "", $string);
echo $result;
?>
输出:<a href="/title/tt3110958/" style="color:#666" >
我用过:'$ result = preg_replace('/ \?[^ \“] + /',”“,$ string);'。 –
您可以使用str_replace()
为
例子:
$myStr = "foo? bar???";
$myStr = str_replace("?","\"",$myStr);
它不会删除url的查询字符串。 – Mohammad
我认为'$ str'是未定义的变量。 –
有一堆不同用PHP做这件事的方法。你有什么尝试? –
@JohnConde我更新我的问题! –
使用'/ \?[^“] + /'来代替 – Mohammad