Regular Expression (preg_match_all)

Posted by Helena on Stack Overflow See other posts from Stack Overflow or by Helena
Published on 2011-11-23T17:32:05Z Indexed on 2011/11/23 17:51 UTC
Read the original article Hit count: 407

This is my code:

<?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>';        

}  
?>

It's not working. I want to exclude every match that has a whitespace before or after the Link (with the ID). I used \S for this.

For example if:

$matchWith = " http://videosite.com/ID123 ";

it should not display anything.

Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-match