<?php
function findAndReplace($arr) {
return '<strong>'.$arr[1].'</strong>';
}
$inputText = 'Why use <a href="#" style="padding-left:5px"> PHP </a>?';
echo "<br />Input is: <br />";
echo $inputText;
$returnText = preg_replace_callback('@<a(?:.*)>(.*)</a>@isU', 'findAndReplace', $inputText);
echo "<br /><br />Output will be: <br />";
echo $returnText;
?>
Input is:
Why use PHP ?
Output will be:
Why use PHP ?
hi - this is an awesome function and Im looking for something similar to replace spaces in my urls - can this be done using a call back function? how would one do it?
ReplyDeletestrip_tags($inputText);
ReplyDeleteis easier than this.
Thanks
ReplyDelete