- preg_replace_callback: documentation ( source)
- urldecode: documentation ( source)
- end: documentation ( source)
<?php
$_content = '<a href="https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/p100x100/10394047_10202106066684824_80590983553430220_n.jpg?oh=fcccf17086a3593d926a100c9a82f898&oe=546AACC9&__gda__=1416199983_da92aa7319b2636ad2887652e2f9a10e">https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/p100x100/10394047_10202106066684824_80590983553430220_n.jpg?oh=fcccf17086a3593d926a100c9a82f898&oe=546AACC9&__gda__=1416199983_da92aa7319b2636ad2887652e2f9a10e</a>';
$_fbcdn_imagelink_pattern = '#<a href=\"https://fbcdn([^\?\'"]*?)(.jpg|.gif|.png)\?([^\'"]*?)[^>]*>([^<]*?)</a>#i';
function fbcdn_link2img( $matches ) {
$ret = "";
if(!empty($matches)) {
$ret = "<img src=\"".urldecode(end($matches))."\">";
}
return $ret;
}
$_content = preg_replace_callback($_fbcdn_imagelink_pattern, "fbcdn_link2img", $_content);
echo $_content;