假设我有以下href:
.... href="http://localhost/centboox/usedtextbooks/desc/30" ....
我想通过所有这些并在关闭 href 的双引号之前添加* * :
... href="http://localhost/webname/pagename/desc/30*******" ...
星号代表一些输入,例如 ?q=all&a=search_text
我如何通过 PHP 中的 preg_replace 做到这一点。
谢谢
假设我有以下href:
.... href="http://localhost/centboox/usedtextbooks/desc/30" ....
我想通过所有这些并在关闭 href 的双引号之前添加* * :
... href="http://localhost/webname/pagename/desc/30*******" ...
星号代表一些输入,例如 ?q=all&a=search_text
我如何通过 PHP 中的 preg_replace 做到这一点。
谢谢
$result = preg_replace('/href="[^"]*/', '\0********', $subject);
如果您要始终将其连接到字符串的末尾,有什么理由不能仅仅连接?
// Assuming you're array is already filled out...
$somethingToAppend = "?q=all&a=search_text"
foreach($hrefs as $key => $value) {
$hrefs[$key] = $value + $somethingToAppend;
}
干杯
这是一个简单的例子:
$href = <<<EOHTML
<a href="test.html?value=one">LINK</a>
EOHTML;
$href = preg_replace("/href=\"([^\"]*)\"/",
"href=\"$1**\"", $href);
echo $href;
在我正在寻找的正则表达式模式中href="(something)",我将其替换为href="(something)**".
这是 preg_replace 的示例,它可能对您有用。检查下面的链接