這是我的代碼:正則表達式(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