这是我的代码:正则表达式(preg_match_all)
<?php
$matchWith = "http://videosite.com/ID123";
preg_match_all('/\S\/videosite\.com\/(\w+)\S/i', $matchWith, $matches);
foreach($matches[1] as $value)
{
print '<a href="http://videosite.com/'.$value.'">
Hyperlink
</a>';
}
?>
它不工作。 我想排除链接之前或之后具有空格的每个匹配(带有ID)。 为此,我使用了\S
。
例如,如果:
$matchWith = " http://videosite.com/ID123 ";
它不应该显示任何内容。
谢谢。
使用此代码我总是会得到一个空白页。谢谢 – Helena
现在我不再有一个空白页面,但它仍然显示链接,如果像'$ matchWith =“http://videosite.com/ID123”;' – Helena