abasit83 abasit83 - 6 months ago 13
PHP Question

I have to remove static+dynamic text from string in php

I have to remove

pic.twitter.com/yzvksTiMjH
from my news titles.

It appears anywhere in the title.

pic.twitter.com/
is static but the text after slash (
/
) is not static and it always have 10 alphabets.

Need Help ...

Thanks

Answer

Use preg_replace

/\bpic.twitter.com\/\w{10}\b/

This regex:
- \b : boundary
- pic.twitter.com : literals
- \w{10} : any word with length of 10