Here's my goal: when a user enters some text into a textbox form (like posting this message) and presses the enter key twice to create a new paragraph, I'd like to replace those two enters with some HTML tags like </p><p>.
I found this online at the php.net site:
Code: Select all
<?php
$news = ereg_replace("\r?\n\r?\n", "</p><p>", $news);
$news = ereg_replace("\r?\n", "<br />", $news);
$news = "<p>".$news."</p>";
?>1. I don't understand the syntax of "r?\n\r?\n".
2. It doesn't work for me.
As far as I can determine from online resources, Macs and PCs issue line feeds differently and I do want this code to be cross-platform compatible. I thought they were \r\n and \n\r but I may not be correct.
I'm also reading that preg_replace is a faster option in most circumstances, but I can't determine if the same syntax is used for both preg and ereg.
Can anyone shed a bit of light on this subject for me? Point me to some beginner friendly resources?
Thanks!