WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Newline Functions
Categories : PHP, HTML and PHP, Regexps Click here to Update Your Picture
Vinod Mohan
Date : Dec 07th 2008
Grade : 2 of 5 (graded 3 times)
Viewed : 9001
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Vinod Mohan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

PHP has a function nl2br for converting newlines to html <br/>. This function is really useful when asking for user comments / feedback, because by using

<?php
$comment
= nl2br(strip_tags($comment));
?>


we can remove the unwanted html tags and at the same time retain the line breaks. But the function does not actually replace the "\n" with <br/> but with "\n<br/>". Hence you may run intro trouble, if you save the data in flat file. Also there is no equivalent br2nl.

So here is my functions nl2break, which converts "\n" to "<br/>" and break2nl, which converts <br/> back to "\n". Also included is a function nl2para, that converts two consecutive newlines to a paragraph and a single newline to break.

<?php
function nl2break($str){
     return
preg_replace('#\r?\n#', '<br />', $str);
}

function
break2nl($str){
     return 
preg_replace('/\<br\s*\/?\>/i', "\n", $str);
}

function
nl2para($str){
     
$str preg_replace(array('#(\r?\n){2,}(\s+)?#', '#\r?\n#'), array("</p><p>", '<br/>'), $str);
     return !empty(
$str) ? "<p>$str</p>" : '';
}
?>



PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Parse html (title :: meta)
Categories : PHP, HTML and PHP, Regexps
php table decoder used to convert an html table to individual tokens through regular expressions
Categories : PHP, Regexps, HTML and PHP
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
Form input return conformance
Categories : HTML and PHP, PHP, Regexps
How to use regular expressions to get the list of links from an HTML page
Categories : PHP, Regexps, HTML, HTML and PHP
Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used.
Categories : HTML and PHP, PHP, Date Time
Amazon book cover handling
Categories : HTML and PHP, PHP, MySQL, Ecommerce
How to build a search query for any N number of words in a search string
Categories : PHP, Regexps, Search Engines, Search
If you want to create select buttons featuring current date this example will show you how...
Categories : Date Time, HTML and PHP, PHP
Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
Website Engine
Categories : PHP, HTML and PHP, Templates
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP