Jump to content

Archived

This topic is now archived and is closed to further replies.

Gordon Werner

eregi_replace Question ...

Recommended Posts

I have a bunch of code that requires users to enter text.  To avoid certain problems, I restrict the tags they can use to mark up the text ... using bracket tags instead of html tags like

[b]...[/b]

which I then replace at runtime using eregi_replace.

 

this is not a problem for things like bold text ...

 

$description		=	eregi_replace('\[b]([^]]*)\[/b]', '<b>\1</b>', $description);

 

but how do I handle things like bullet lists where I want to let the user only have to enter

[*]

?

 

right now, all I do is this:

 

$description		=	eregi_replace('\[\*]', '<li>', $description);

 

but this makes the XHTML validation fail (no closing </li> tags) ...

 

is there an easy way that I can have the code auto-insert the </li> tag? and how would the above code snippet have to change?

 

Thanks

 

G.

Share this post


Link to post
Share on other sites

The easiest thing to do would be to make the user mark it up like any other tag:

 

[*]something

 

that is how most forums do it.

 

p.s. - stop using posix functions (ereg**) they are deprecated and are removed from the php core as of v6.  Use the pcre functions (preg**) instead.

 

 

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.