Page 1 of 1

please help with regular expression

Posted: Mon Mar 31, 2014 9:10 am
by gt3000
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]

Re: please help with regular expression

Posted: Sat May 10, 2014 8:35 pm
by icey2k
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.