On Thursday 19 August 2004 08:11, Mag wrote:

> I dont know regex very well but I am using one below
> that I modified from the web:

>   return eregi_replace('<!-- .*Hstart("|\')?([^
> "\']*)("| \')?.*>([^<]*)<!-- Hend -->', '', $string);

> Its working great for 1 file, but when I put it into a
> for loop to handle multiple files....it takes ages for
> 10 files and sometimes just "hangs".

1) regex functions are slow, and can gobble up lots of memory
2) the POSIX regex functions are even slower (than the PCRE functions)


I suggest that you use simple string functions, with this general outline:

- loop through the file line by line looking for the start-tag
- set FLAG
- if FLAG is set and line does not contain the start-tag then write the line 
- if FLAG is set and line contains start-tag then unset FLAG, ignore the line
- if FLAG is not set and line does not contain end-tag then ignore the line
- if FLAG is not set and line contains end-tag then set FLAG, ignore the line

If you're allowing the start-tags and end-tags to appear in lines along with 
other text then your task is slightly more complicated and you will have to 
allow for that when processing the lines containing those tags.


If your files are relatively small then its even easier. Read the whole file 
into a string then use strpos() or stripos() along with substr() - and 
whatever other useful string functions you find.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
Artificial intelligence has the same relation to intelligence as
artificial flowers have to flowers.
                -- David Parnas
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to