Jump to content

[SOLVED] eregi? or is there something better..


origaflux

Recommended Posts

Sorry if I should've posted this elsewhere, but I don't think anyplace is really any more pertinent.

Here's the scenario.  I have my site with a blog on it.  I employ the html comment tags <!-- and --> in my posts to create private text that only I and one good friend of mine can see.  Example:

 

post text blah blah.  <!-- private text blah --> post text.

 

I use eregi to remove the text between the tags (and the tags as well) from the post so not even people who snoop around in my html source would be able to see the comments.

It works out just fine, until I do something like this:

 

post text blah <!-- private text 1 --> post text 2 <!-- more private text --> more post text.

 

When I use eregi to remove the tags and everything between them, it looks like:

 

post text blah  more post text.

 

Note the absence of "post text 2" which was between the two private comments.

I know why eregi is doing that, but I want to fix it so it only removes the tags and comments themselves and nothing between.

my search for the tags is:

 

eregi("<!--.*-->", $post);

 

I can't wrap my head around how to manipulate this to accomplish my ends.

Any help is appreciated and by all means please ask for clarification if I explained oddly.

Link to comment
Share on other sites

Oops.  I lied.  The previous item did not fix it.

However, thanks anew mjdamato, because your method works just fine.

The problem came when i was trying to use it with eregi which is POSIX regex, which is not Perl regex, which means it's not compatible with that syntax.

 

Switching to preg_match worked fine:

 

preg_match("/<!--.*?-->/i", $post);

 

So, now, thanks for the DIRECT help, mjdamato.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.