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 Quote Link to comment Share on other sites More sharing options...
boom Posted November 28, 2007 Author Share Posted November 28, 2007 any idea's? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.