New Webmaster Tool – The Regular Expression Editor

WarkenSoft Productions is proud to announce the development of a new tool for use on our site. The Regular Expression editor will allow you to test and edit any regular expressions that you have been struggling with to develop. Made available for free to our visitors, we hope you enjoy the tool and find it to be useful.

If you have any suggestions for improvements or comments about it, feel free to leave them in the comments area below. Also, we’re always on the look out for good regular expressions, so if you feel that you have one or a few that might be useful to the other visitors to this site, feel free to mention them in the comments.

Related Reading:

PHP Cookbook: Solutions & Examples for PHP ProgrammersPHP Cookbook: Solutions & Examples for PHP Programmers

Want to understand a certain PHP programming technique? Or learn how to accomplish a particular task? This cookbook is the first place to look. Wit... Read More >

PHP Objects, Patterns, and PracticePHP Objects, Patterns, and PracticeAided by three key elements: object fundamentals, design principles, and best practices, you'll learn how to develop elegant and rock solid systems us... Read More >
The Joy of PHP: A Beginner's Guide to Programming Interactive Web Applications with PHP and mySQLThe Joy of PHP: A Beginner's Guide to Programming Interactive Web Applications with PHP and mySQLThird Edition now with bonus chapters. Have you ever wanted to design your own website or browser application but thought it would be too difficult o... Read More >

PHP Function to Convert LineBreaks to NewLines

While PHP has a very nice little function (nl2br) to convert newlines (\n) to line breaks (<br>), moving in the opposite direction is not quite so easy. This function should hopefully help to allow you to convert line breaks to new lines.

<?php

/* This function will convert line breaks or other tags passed in the $tags variable
to linebreaks.  Multiple $tags must be separated by spaces, and must consist of the
regular tag text.  Ie. $result = br2nl($text_to_filter, "br p blockquote") */
function br2nl($text, $tags = "br")
{
 $tags = explode(" ", $tags);

 foreach($tags as $tag)
 {
 $text = eregi_replace("<" . $tag . "[^>]*>", "\n", $text);
 $text = eregi_replace("</" . $tag . "[^>]*>", "\n", $text);
 }

 return($text);
}

// Usage:
 $text_to_filter = "<p>This is my <br>sample<br>text.  The default code listed here " .
"should replace the br's with new lines.</p><p>The second example is more advanced, " .
"stripping out both the BR's as well as the P tags.</p>";

 // Example of replacing BR tags (default)
 $result = br2nl($text_to_filter);
 echo "<pre>$result</pre>";

 // Example of replacing both BR and P tags
 $result = br2nl($text_to_filter, "br p");
 echo "<pre>$result</pre>";

?>

Related Reading:

Php: Programming, Master's Handbook:  A TRUE Beginner's Guide! Problem Solving, Code, Data Science,  Data Structures & Algorithms (Code like a PRO in ... engineering, r programming, iOS development,)Php: Programming, Master's Handbook: A TRUE Beginner's Guide! Problem Solving, Code, Data Science, Data Structures & Algorithms (Code like a PRO in ... engineering, r programming, iOS development,) PHP Programming Like a PRO! “ this book makes it super easy to understand what you are doing and it is super easy to follow. “ - Emily Whi... Read More >
Murach's PHP and MySQL, 2nd EditionMurach's PHP and MySQL, 2nd Edition

"I can't count how many PHP books I have purchased over the years trying to learn the language. Murach's was the first book that helped me grasp th... Read More >

PHP Cookbook: Solutions & Examples for PHP ProgrammersPHP Cookbook: Solutions & Examples for PHP Programmers

Want to understand a certain PHP programming technique? Or learn how to accomplish a particular task? This cookbook is the first place to look. Wit... Read More >