[Solved] Using preg_replace_callback with a href - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: [Solved] Using preg_replace_callback with a href (/showthread.php?tid=66521) |
[Solved] Using preg_replace_callback with a href - wolfgang1983 - 10-31-2016 In my preg_replace_callback I can allow some elements to be showing in preview using the preg_replace_callback How ever when the user has typed in a link lets say <a href="http://www.example.com">Example</a> The preview will only put out <a href="http://www.example.com">Example Is there any way I can integrate this PHP Code: preg_replace("~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~","<a href=\"\\0\">\\0</a>", $string) Into the code below PHP Code: public function preview() { RE: Using preg_replace_callback with a href - InsiteFX - 10-31-2016 If it's dropping the end of the link do a check and if it's a link concat the end on to it. RE: Using preg_replace_callback with a href - wolfgang1983 - 10-31-2016 (10-31-2016, 06:34 AM)InsiteFX Wrote: If it's dropping the end of the link do a check and if it's a link concat the end on to it. How do I do that? RE: Using preg_replace_callback with a href - InsiteFX - 10-31-2016 PHP Code: $string .= 'What you need here'; Do that after you check the string and do your replacing. RE: Using preg_replace_callback with a href - wolfgang1983 - 10-31-2016 (10-31-2016, 02:46 PM)InsiteFX Wrote: I tried that not worked RE: Using preg_replace_callback with a href - wolfgang1983 - 11-01-2016 Update I have added it in like this now but now prints it out twice PHP Code: $string = $this->input->post('question'); RE: Using preg_replace_callback with a href - InsiteFX - 11-01-2016 Try this one: PHP Code: $new_data = preg_replace_callback("#</?(pre|code|h1|h2|h3|h4|h5|h6|b|strong|i|u|hr)>|[<>]#", function ($match) { RE: [Solved] Using preg_replace_callback with a href - wolfgang1983 - 11-01-2016 I did a couple changes on my script and got it working |