Mark Mark - 6 months ago 32
PHP Question

In PHP, Is it possible to extract a twitter status from a string that has surrounding BBCode?

I basicly have the following string

$string = 'Blah blah blah [url][/url] blah blah';

Im trying to do a preg_replace on this $string to make the output say

Blah blah blah TWITTER Link blah blah

So far I have this non-working line in my code

$string = preg_replace("/^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)$/","TWITTER Link $1",$string);

Any ideas??


You can use this preg_replace code:

$re = '~\[url\]https?://twitter\.com/\S+\[/url\]~'; 
$str = "Blah blah blah [url][/url] blah blah"; 

$result = preg_replace($re, "TWITTER Link", $str);

//=> Blah blah blah TWITTER Link blah blah 

RegEx Demo