note 43174 deleted from function.str-ireplace by tomsommer
| From: | tomsommer@php.net | Date: | Fri, 11 Jun 2004 23:06:05 +0000 |
| Subject: | note 43174 deleted from function.str-ireplace by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70949@lists.php.net to get a copy of this message | ||
Note Submitter: jonathonkeogh@rapidplay.com
----
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>