From: skate [EMAIL PROTECTED]
$contents = preg_replace( |item.*?.$file..*?/item|si, ,
$contents );
okay, so i figured out that it's matching the first occurence of item
which will always be the first record and then going on to match the $file
and deleting everything between. obviously not
skate wrote:
$contents = preg_replace( |item.*?$file.*?/item|si, , $contents );
it's being run on an XML file, where each entry is item../item with
a $file pointer in there.
it works okay, except for the fact that it deletes that record, and every
record before it. i can't figure out why
$contents = preg_replace( |item.*?.$file..*?/item|si, ,
$contents );
okay, so i figured out that it's matching the first occurence of item
which will always be the first record and then going on to match the $file
and deleting everything between. obviously not what i want.
without giving item a
preg_replace(|item.*?$file.*?/item|si,,$contents)
news
item
titlefhh/title
date1060205191/date
texthhh/text
filexml/news/1060205191.xml/file
/item
item
titlefgjghjh/title
date1060205186/date
textfgjh/text
filexml/news/1060205186.xml/file
/item
item
Not sure if I understand you correct but
the way you wrote your replace pattern the result should be
news/news.
If you want just the file to be replaced you have to use something like
preg_replace(|item.*?($file).*?/item|si,'\\1',$contents)
no, i want just the whole item/item replaced for
And what about [^]* -if there are no html tags
not thought about that, but XML tags, not HTML tags... does that make any
difference?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
- Original Message -
From: skate [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, August 06, 2003 3:16 PM
Subject: [PHP] greedy preg
$contents = preg_replace( |item.*?$file.*?/item|si, ,
$contents );
it's being run on an XML file, where each entry is item../item
with
Do you need to use .*?? If there will be only white characters, use
\s* instead.
unfortunately there's some content either side of $file before item/item
this content is different for each item, so i can't define it in the
pattern.
--
PHP General Mailing List (http://www.php.net/)
To
Do you need to use .*?? If there will be only white characters, use
\s* instead.
skate wrote:
$contents = preg_replace( |item.*?.$file..*?/item|si, ,
$contents );
okay, so i figured out that it's matching the first occurence of item
which will always be the first record and then going on to
You cannot store file pointers. If you output the variable it's going to
look something like Resource ID #1 which is meaningless except to the
instance of the script that created it. Or did you mean something
different
by $file pointer?
sorry, wrong words...
when i meant $file is equal
skate wrote:
What are the possible values of $file? Are you looking to replace just a
specific occurance of a $file between item tags? Maybe this will help:
$contents = preg_replace(|item[^]*$file[^]*/item|si,,$contents);
or just use the 'U' modifier for ungreedy...
i'm looking to replace the
And what about [^]* -if there are no html tags
skate wrote:
Do you need to use .*?? If there will be only white characters, use
\s* instead.
unfortunately there's some content either side of $file before item/item
this content is different for each item, so i can't define it in the
pattern.
Yeah, it should be. What kind on content can be around $file and also
within the item tag?
here's a snip of the xml file...
it's finding the $file correctly, but deletes all records from the beginning
of the file onwards. it leaves the xml file with valid xml ... news at the
start... so for
What are the possible values of $file? Are you looking to replace just a
specific occurance of a $file between item tags? Maybe this will help:
$contents = preg_replace(|item[^]*$file[^]*/item|si,,$contents);
or just use the 'U' modifier for ungreedy...
i'm looking to replace the entire
14 matches
Mail list logo