Str_replace static text with dynamic text for each result
Posted: Thu Jul 17, 2008 3:59 pm
Hello,
I've yet to find a suitable answer for this:
I have a page that prints from a DB and has active text that a user can modify inline. When the user mouses over, there's a tooltip window with some options and the selected one updates the text in the paragraph
Ex: The patient hurt his (left/right/both) hand.
The tooltip for the parentheses lets the user click one of the three and the sentence updates with the choice.
My problem is this: the text from the DB column has that parenthetical statement and I want to use 'str_replace' to replace the text with a span that activates the tooltip. The trouble is that I need an unique ID for each replacement but 'str_replace' only does one iteration.
The most basic form:
My trials and tribulations:
The bottom example actually does work in that it generates a random element ID however, the 2nd and 3rd elements for some weird reason (user error?) have the same ID but the rest are ok.
Any ideas?
I've yet to find a suitable answer for this:
I have a page that prints from a DB and has active text that a user can modify inline. When the user mouses over, there's a tooltip window with some options and the selected one updates the text in the paragraph
Ex: The patient hurt his (left/right/both) hand.
The tooltip for the parentheses lets the user click one of the three and the sentence updates with the choice.
My problem is this: the text from the DB column has that parenthetical statement and I want to use 'str_replace' to replace the text with a span that activates the tooltip. The trouble is that I need an unique ID for each replacement but 'str_replace' only does one iteration.
The most basic form:
Code: Select all
$DB_Column_Text = str_replace("(A/B/C)" , "<span class=ttipshower onmouseover=showtool(this.id) >(A/B/C)</span>" , $DB_Column_Text);
Code: Select all
function produceavalue($what) {
return "<span class=ttipshower onmouseover=showtool(this.id) id=".rand().">$what</span>"
}
$DB_Column_Text = str_replace("(A/B/C)" , produceavalue("(A/B/C)"); , $DB_Column_Text);
The bottom example actually does work in that it generates a random element ID however, the 2nd and 3rd elements for some weird reason (user error?) have the same ID but the rest are ok.
Any ideas?