Problem with this function FormatText ----------------- Hi guys, I have a problem with this function called formatText. It helps me churns the data input into my mysql database into proper paragraphs, takes care of the accented characters etc.. it's perfect, except for one point: I cannot add <a href></a> into my text. Well I CAN, but it will append the page folder to whatever I put. Example: - When I have this text "And here we go to Google". - I insert the text with the <a> tag into my mysql database: And here we go to <a href="http://w w w xxx>">Google</a> [note, this is only an example so I'm not putting the real address here]. My web addres is http://www.example.com/thispage.php - on the page that is churned out, the text is welll formatted but the link turned out to be "http://www.example.com/http://w w w xxx". - Which is to say it appends whatever URL the page is located to the link within the text. Why is this happening? Here is the formatText function: _________________ <? function formatText ($text, $addPara=1, $addBreakLine=1, $stripTags=0, $allowedTags='<a>,<em>,<strong>,<i>,<b>') { $text = trim ($text); # translate all accented characters to HTML entities # but keep all HTML tags $table = get_html_translation_table (HTML_ENTITIES); $table['<'] = '<'; $table['>'] = '>'; $text = strtr ($text, $table); # strip all HTML tags if the param $stripTags is set to 1 # keep the tags that are set in the param $allowedTags if ($stripTags) { if ($allowedTags) { $text = strip_tags ($text, $allowedTags); } else { $text = strip_tags ($text); } } # add <p> if the param $addPara is set to 1 (default) if ($addPara) { $textElements = preg_split ("/\n(\s)+/U", $text); $newText = ""; foreach ($textElements as $item) { #be sure to strip control chars $item = trim ($item); if ( strlen ($item) != 0 ) { $newText .= "<p>$item</p>"; } } $text = $newText; } # add <br> if the param $addBreakLine is set to 1 (default) if ($addBreakLine) { $table = null; $text = nl2br($text); # nl2br will strip the 'n' after the </p>, add it here # to have a nice formatted HTML source $table["</p>"] = "</p>\n\n"; $text = strtr ($text, $table); } return $text; } ?>
You do not appear to be changing the URL in the formatText() function. The change is happening somewhere else in your system. I would take a look at the code which renders the pages or which reads the information out of the database. You may be able to see where it is rewriting URLs.
Hi there! No, because the other links on the page are working fine. Just the bit where I use the formattext function: http://www.ei-ie.org/en/news/show.php?id=199&theme=hivaids&country=global Any idea what's happening?