PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
But chaos ensues if there's line breaks in the text. There's got to be a simple way to match the entire entry from <entry id...> to </entry> no matter what text is in the <text> field - multiple line breaks, question marks, blah blah blah. Right?
Any advice?
Calipoop wrote:Thanks for the reply red.
I tested it out - no luck, it didn't match anything. I'm gonna take a look at your expression as a starting point.
As mentioned, the regex assumes that the text you are matching is the same as the sample you detailed above or more specifically that the opening and closing 'entry' tags are at the very begining of a new line.
It doesn't stink, it is by design. Personally I feel it is better to create your regex to be as restrictive as possible then open it as and when needed rather than using the 'match all' dot syntax and then running into an unforeseen pattern match and loosing data.
HAH! sorry bout the stink comment, I'm just frustrated. Anyway, the new expression you gave looks to be close, but your expression is doing something similar to what my latest expression is doing:
it's deleting everything before and after the one entry that I want deleted. I get a whole slew of repeating DELETED all 1 space away from eachother. I had been getting a similar result as this except instead of spaces separating the DELETED it was a single letter, presumably from the previous entries.
Thanks again for your help - this is day two of my fight. I wonder if the deleting BEFORE and AFTER is a key into the error? I print out the $idEntry each time and it does in fact match exactly one entry in the fields. Don't understand why it's grabbing everything...!
deletes only the entire first entry. The '1' parameter limits it to one match.
Again, I match the exact value for $idEntry to the value in the xml file, but the replace function is just not finding it. The $idEntry value in the xml file is definitely on a different line than from where the search starts. I think that is the problem...?
with the above expression, I've substituted the exact value of $idEntry in the match expression, and it works. So this would mean that this part of your expression:
I'd more inclined to think that the value of $idEntry is not being set right at your end. Have you tried to echo this variable and confirmed it's value is as expected?
yeah, I've definitely confirmed the entry id every time - it's being set correctly even without spaces and everything. printed out EXACTLY:
entry id="1098494923933"
could it be getting confused cause there are double quotes in the variable? Maybe the double quotes need escaping or something?
I can supply the xml if you think it will help, but God, I was avoiding it cause it's a complete mess. The xml code is functional, but the formatting is a disaster. I think the fact that I could extract the entry without the variable means it's a variable problem?
the difference in mine is there's no /m modifier and I've added the 1 parameter cause there will only be 1 unique entry. Are those differences likely to make a big difference? I must admit, (and as you can probably tell) I'm not very experienced with modifiers and regex in general...
The 'm' modifer is not required for the regex you are using, my use of that modifer in my last offering was a mistake on my part (copying and pasting and not paying attention). The regex in my second example would be the one to use.
I am still confused as to why you are needing to specify the '1' parameter as this should not be the case. But then again without actually seeing the file you are working with it is difficult to know exactly what is going on.
If it works for you then perhaps you should just accept it but, to me it doesn't seem right so I suspect there may be another underlying problem.