Hi dear better php!
I have a problem and hope for your help to resolve it.
1.I need to get a code from the youtube link (11 digits, which comes after watch?v=).
2.And remove all text which can be before and after the link, also the text could not be on a page, so anyway i need to get that video code.
For example: "lorem ipsum bla bla htttp://www.youtube.com/watch?v=12345678911 lorem ipsum blablabla".
I was wrote some expression but it doesnt work well :
[syntax=php]
$new_text = preg_replace('/.[https:\/\/www\.youtube\.com\/watch\?v=].*https:\/\/\www\.youtube\.com\/watch\?v=*(.{11}).*/s', '<img src=timthumb.php?src=http://img.youtube.com/vi/$1/maxresdefault.jpg&h=90&w=230 />', $profile_post_content);
[/syntax]
please help with regular expression
Re: please help with regular expression
You can use substr() ?
[syntax=php]
$str = "http://youtube.com/watch?v=12324567";
$start = strpos($str, "=");
$newstr = substr($str, $start);
$newstr[0] = "";
echo $newstr;
[/syntax]
Probably not the best way of doing it, but it does the job.
[syntax=php]
$str = "http://youtube.com/watch?v=12324567";
$start = strpos($str, "=");
$newstr = substr($str, $start);
$newstr[0] = "";
echo $newstr;
[/syntax]
Probably not the best way of doing it, but it does the job.