| Home > Computer & I'net > Matching/Replacing... |
|
|
|||||||||||||||
|
|
|||||||||||||||
|
||||||||||||||||
Matching/Replacing | |
As seen on the previous tutorial pages, ereg( ) and eregi( ) are used to find patterns. Taking this to the next level will allow you to find a pattern and replace it with a new value. This is using ereg_replace( ) and eregi_replace( ). The i has the same effect as before, case insensitive.
The replace command looks like this : eregi_replace(pattern,replacement,search_area); Very similar to the normal eregi command only it has an extra parameter in the middle. A replacement can be used for many different uses such as... 1. Taking an entered URL and making it a clickable one. 2. Replacing a text smilie into an image one. 3. Replacing bad words with *@!%. Most of these examples would be taking some user input from a form and processing it to a webpage or email. We'll do an example using the smilies. On the form page <form method="post" action="changeit.php"> <input type="text" name="entry"> <input type="submit" value="submit"> </form> changeit.php <?php $pattern = ":)"; $replacement = "<img src="smilie.gif">"; $entry = ereg_replace($pattern,$replacement,$entry); echo "$entry"; ?> ----------------- Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission. | |
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|