Insert HTML Tags in String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Insert HTML Tags in String

Post by TryAgain2 »

I am looking for a way to insert HTML tags into a string. For example, if I want to highlight part of a user's input how can I wrap it in HTML tags to underline or change its colour?

Example:

User input:

This is an example.

Then I want to hight one word:

This is an example.


I cannot find any string function/s that will do this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

substr_replace(), preg_replace() among others can do this.
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post by TryAgain2 »

Thanks, I thought I needed to insert the text, but I see now that the same thing can be accomplished with substr_replace.
Post Reply