|
-
Jun 3rd, 2010, 06:07 AM
#1
Re: Optimizing regular expression
Depending on how you want it done you could even use the strip_tags PHP function.
-
Jun 3rd, 2010, 07:16 AM
#2
Re: Optimizing regular expression
 Originally Posted by sciguyryan
Depending on how you want it done you could even use the strip_tags PHP function.
uhh? all strip_tags() does is remove HTML tags. it doesn't remove content, which means that you wouldn't be able to use it to parse anything. it's used for sanitation of user input, usually.
regular expressions are the way to go in this case.
-
Jun 3rd, 2010, 07:52 AM
#3
Re: Optimizing regular expression
 Originally Posted by kows
uhh? all strip_tags() does is remove HTML tags. it doesn't remove content, which means that you wouldn't be able to use it to parse anything. it's used for sanitation of user input, usually.
regular expressions are the way to go in this case.
No. But had you looked on the page, there is a function on there that does. Such as:
PHP Code:
function strip_selected_tags($str, $tags = "", $stripContent = false) { preg_match_all("/<([^>]+)>/i", $tags, $allTags, PREG_PATTERN_ORDER); foreach ($allTags[1] as $tag) { $replace = "%(<$tag.*?>)(.*?)(<\/$tag.*?>)%is"; $replace2 = "%(<$tag.*?>)%is"; echo $replace; if ($stripContent) { $str = preg_replace($replace,'',$str); $str = preg_replace($replace2,'',$str); } $str = preg_replace($replace,'${2}',$str); $str = preg_replace($replace2,'${2}',$str); } return $str; }
... and it also makes for a pretty interesting demo of RegExp too.
-
Jun 3rd, 2010, 08:54 AM
#4
Re: Optimizing regular expression
 Originally Posted by sciguyryan
No. But had you looked on the page, there is a function on there that does.
What you said -- that you could use strip_tags() -- is still incorrect.
If you're going to point out that a function posted in the comments of the strip_tags() documentation might be useful, then you should probably say that it actually has nothing to do with strip_tags() and link to the comment itself. Otherwise, you're just misinforming.
Should I even mention that the function you posted doesn't even do what was needed (or what you suggested it did), anyway? It was written that way to support self-closing tags (like <input />).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|