Hello everyone,
This is my first piece of php I have written, and after a few days of trail and error I came up with this code to replace certain words in an article for links.
I have searched for a ready made code for this but never found one so I tried to write one myself...
Since I am new to this I can hardly believe it seems to work.. But is there something I have overlooked?
For instance, would this still work if I have, lets say, a $wordlist array of a 1000 words, and an $article of 3000 words?
The following code makes the following text:
Hello, I am in a gReat place to say good morNiNg
into:
Hello, I am in a Great place to say good Morning
<?php
// ---------------------------------------------------------
// GET FORM INFO
$article = "Hello, I am in a gReat place to say good morNiNg"
//----------------------------------------------------------
// LIST OF REGIONS AND THE LINKS THAT REPLACE THEM
$wordlist = array(
0 => 'Hello',
1 => 'Great',
2 => 'Morning',
);
$linklist = array(
0 => '<a href=hello.html>Hello</a>',
1 => '<a href=newyork.html>Great</a>',
2 => '<a href=morning.html>Morning</a>',
);
//----------------------------------------------------------
// PUT THE LINK IN A NEW ARTICLE
$newarticle = str_ireplace($wordlist, $linklist, $article);
// ---------------------------------------------------------
// PRINT HTML
print('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Form Results</title>
</head>
<body>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
');
print("
<td align=\"left\" valign=\"top\">
<b>Name of Region:</b>
</td>
<td align=\"left\" valign=\"top\">
$newarticle
</td>
</tr>
</table>
</body>
</html>
");
?>
Thanks for all your help....