note 88622 added to function.ereg-replace

From: Date: Sun, 01 Feb 2009 11:55:20 +0000
Subject: note 88622 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-150056@lists.php.net to get a copy of this message
This function makes links unclickable, read the comments: <?php function strip_urls($text, $repPat) { if(!$repPat){ $repPat = "text [url]"; } $aimpstr = 'PHP_STRIP_URLS_FUNCTION_BY_REAL-PHP-GEEK'; //change $aimpstr to anything you want. $impstr = md5($aimpstr); $text = str_replace('</a>', '</a>' . $impstr, $text); $text = explode($impstr, $text); $n = 0; $texta = array(); $repPat = str_ireplace(array('text', 'url'), array('\\4', '\\2'), $repPat); foreach ($text as $text) { $texta[$n] = ereg_replace("<a(.*)href=\"(.*)\"(.*)>(.*)</a>", $repPat, $text); $n++; } $textb = implode("</a>", $texta); return $textb; } //EXAMPLES: $string_of_text = '<a href="http://www.php.net/">PHP</a> rocks. <a href="http://www.apache.org/">Apache</a> also!'; echo strip_urls($string_of_text, "text"); echo strip_urls($string_of_text, "url"); echo strip_urls($string_of_text, "text [url]"); echo strip_urls($string_of_text, NULL); ?> ---- Server IP: 92.48.74.199 Probable Submitter: 59.95.28.60 ---- Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php Edit -- https://master.php.net/note/edit/88622 Del: integrated -- https://master.php.net/note/delete/88622/integrated Del: useless -- https://master.php.net/note/delete/88622/useless Del: bad code -- https://master.php.net/note/delete/88622/bad+code Del: spam -- https://master.php.net/note/delete/88622/spam Del: non-english -- https://master.php.net/note/delete/88622/non-english Del: in docs -- https://master.php.net/note/delete/88622/in+docs Del: other reasons-- https://master.php.net/note/delete/88622 Reject -- https://master.php.net/note/reject/88622 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150056) next »