note 43174 added to function.str-ireplace

From: Date: Fri, 11 Jun 2004 22:39:18 +0000
Subject: note 43174 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-70948@lists.php.net to get a copy of this message
Here's a script that replaces certain words in a posted comment into advertisments. Example, comment sent by HTML form... "...so I'm buying a new car at the weekend. It's been a great day today though..." ...comment edited by PHP... "<a href='/keyword/search/car' alt='Look on the internet for a new car!'>car</a>" "...so I'm buying a new <a href='/keyword/search/car' alt='Look on the internet for a new car!'>car</a> at the weekend. It's been a great day today though..." THIS REQUIRES PHP 5 FOR THIS TO WORK. Filename: postnote_send.php <?php $comment = $_POST['comment']; $name = $_POST['name']; // Add Keywords here, example: $words = Array("car", "job"); // Add links corrosponding with the keywords here, example: $links = Array("/keyword/search/car", "/jobs_with_mycompany.php"); // Notice that the first one of the array above can be done with Apache. // Add a description corrosponding with the keywords here, example: $desc = Array("Look on the internet for a new car!", "Apply for a job with My Company, Inc."); for($x=0;$x<count($words);$x++) { str_ireplace($words[$x], "<a href='{$links[$x]}' alt='{$desc[$x]}'>{$words[$x]}</a>"); } // Convert '<' into HTML characters... $comment = htmlentities($comment); // Print out a thank you notice. print "<p>Thank you, $name, for your comment:<br>$comment</p>"; // Do something else with $comment and $name... ?> ---------- Filename: postnote.php <html> <head> <title>Post a note on our site!</title> </head> <body> <!-- Do header features here, like include a file or something --> <form action='postnote_send.php' method='post'> <p>Your name:<br><input name='name'></p> <p>Your comment:<br><textarea name='comment' rows=10 cols=100></textarea></p> <p><input type='submit' value='Send note!'></p> </form> </body> </html> ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43174 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43174&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43174&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70948) next »