i have an php array like this
$values = array(
"hello" => "12",
"a" => "24",
"grand" => "40",
"mother" => "10"
);
and a string for example
$string = "<p>hello</p><div style="align:center"> i am a grand mother</span>";
Initial text can contains html code. This point is important.
I need to replace all words in string by
<span id="word_id">word</span>
In my example, the result will be:
<p>
<span id="12">hello</span>
</p>
<div style="align:center">i am
<span id="24">a</span>
<span id="40">grand</span>
<span id="10">mother</span>
</div>
The main problem is that it can used for a basic string_replace because it will replaced the word "a" in word "grand" for example . Another things, I need to keep initial html code on my text. And I don't know if I can browse my string text and replace word by word if word exist.