Hello, I have database of words and synonyms words. for example: hello -> hi, welcome, hola, hii. images -> pics, pictures, photos and ect... I'm trying to write a code that get html file from user (e.g: sample.html) and searching for the words in the database that have synonyms words. if the code found word like that it will replace it with random word from its words bank. for example, if the HTMl file contain "<h1>hello</h1> lets talk about <b>images</b>", the result maybe: "<h1>welcome</h1> lets talk about <b>pictures</b>". I start to write the code but I don't know how to search exact word and how to replace it when I find it(if i'm searching for "girl", I don't wont to replace "girlfriend", only "girl"). can anyone help me with that?
of course, input: <h1>hello</h1> lets talk about <b>images</b> output could be: <h1>welcome</h1> lets talk about <b>pictures</b>
This should start you off: <?php $input = "<h1>hello</h1> lets talk about <b>images</b>"; $term = "hello"; $replacement = "welcome"; $output = preg_replace("|<h1>".preg_quote($term)."</h1>|", $replacement, $input); echo $output; ?> PHP:
Hi danx10 Thanks for your help. the code that I wrote was only for example. I don't know how the HTML file gonna look like, that's why I need it to be a general code that fit to all HTML types....