I have a string containing html coming from a form ($postContent). I want to assign a unique id to every image.
I have the following code:
$numImages=substr_count($postContent, '<img');
for($o=0; $o<$numImages; $o++){
$pos = strpos($postContent,"<img");
$postContent = substr_replace($postContent,"<img id='$o' height='50px' onclick='resize(\"$o\")' ",$pos,4);
}
It works fine for the first occurence of an tag, but for the rest it does not work.
Further explaination:
<div><img src="http://image1"><img src="image2"></div>
after going trough my code it gives this:
<div>
<img id='1' height='50px' onclick='resize("1")' id='0' height='50px'
onclick='resize("0")' src="http://image1"><img src="http://image2"></div>
Anyone has any idea what the problem might be?