About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Matching/Replacing...

   Browse by title articles:
   What is hot:

Character Classes

Matching/Replacing

Functions - Intro

Functions - Arguments

Functions - Return Values

Include

Regular Expressions
Good Content: The Key To Search Engine Ranking
Sorting Arrays
Selecting and Evaluating Keyphrases for Search Engine Marketing
Prev articles123456789 10 1112Next articles



Matching/Replacing


Computer & I'net articlesMatching/Replacing

by David Stanley    



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.





Phone Bill




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com