boom Posted November 28, 2007 Share Posted November 28, 2007 Hi i found a script to convert Plain Text to HTML, it works apart from when ever if formats a link it doesn't do it properly: <?php // set source file name and path $source = $_POST['message']; // read raw text as array $data = $source or die("Cannot read file"); // replace special characters with HTML entities // replace line breaks with <br /> $html = nl2br(htmlspecialchars($data)); // replace multiple spaces with single spaces //$html = preg_replace('/\s\s+/', ' ', $html); // replace URLs with <a href...> elements $html = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2" target="_blank">\\1\\2</a>', $html); // start building output page // add page header $output =<<< HEADER <html> <head> </head> <body> HEADER; // add page content $output .= "<div>$html</div>"; // add page footer $output .=<<< FOOTER </body> </html> FOOTER; // display in browser echo $output; ?> say i inputted the following into a text box test 123 blar blar blar blar blar blar blar blar http://www.blar.com the output would be: test 123 blar blar blar blar blar blar blar blar http://www.blar.com<br/ /> and it's that <br/ /> that i want to get sorted the only way i've found is to enclude text on the same line as the link after it. Please help. Cheers Paul Link to comment https://forums.phpfreaks.com/topic/79169-converting-plain-text-to-html-errors/ Share on other sites More sharing options...
boom Posted November 28, 2007 Author Share Posted November 28, 2007 any idea's? Link to comment https://forums.phpfreaks.com/topic/79169-converting-plain-text-to-html-errors/#findComment-400993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.