|Don't ask to ask, just ask|
Bolding search terms ... which might be URLs?by Cody Fendant (Pilgrim)
|on Mar 07, 2011 at 03:30 UTC||Need Help??|
Cody Fendant has asked for the
wisdom of the Perl Monks concerning the following question:
I have a simple, site-specific search engine.
It finds matches in a MySQL database using LIKE.
Then it bolds the search terms before displaying the results to the user. And it also renders URLs clickable.
So, say the user has searched for "perlmonks" and the page contains "you should all go to http://perlmonks.org, it's great!".
We find the term in the database, we bold it, we render the URL clickable and display it to the user, but at this point, the HTML has become this:
Which is of course an invalid URL. How would the Monks approach this problem? ...
Update: I've got some useful and some ... non-useful replies to this. Anonymous monk doesn't seem to understand the question at all. JavaFan doesn't either, although that's my fault because my code was wrong. I updated it.ikegami and mr_mischief, thank you, but I guess it comes down to this: I can't do this with a simple regular expression, can I? I need some kind of parsing where the regular expression would only be applied to things not inside HTML brackets. Or can I do it with an evaluated RHS?