Page 1 of 1

Finding and removing line(s)

Posted: Thu Aug 17, 2006 3:58 pm
by AndrewBacca
Hey, I haven't posted for a while so hello all.

The problem I have is I need to find

Code: Select all

[EDIT?titles=header,Main section,footer,'']
which is at the top of several pages and I need to replace it with nothing but on

Code: Select all

[EDIT?titles=
and

Code: Select all

]
are the same each time the middle will check on each page and I am useless at redex things! so I need some help please :)

Andrew :)

P.S this is what I have got at the moment but it doesn't work

Code: Select all

$this->output =  str_replace('#\[EDIT?title([A-Za-z0-9])\]#', "", $this->output);

Posted: Thu Aug 17, 2006 4:04 pm
by feyd
str_replace() isn't a regex function. :P

This may work.

Code: Select all

$this->output = preg_replace('#^\s*\[edit\?titles=.*\]\s*$#im', '', $this->output);

Posted: Thu Aug 17, 2006 4:10 pm
by AndrewBacca
hey, thanks for the fast reply and that proves my point about not knowing what I am doing lol

but im sorry to say that doesnt do a sauage :lol:

Posted: Thu Aug 17, 2006 4:18 pm
by feyd
It works for me and works as you've specified, it finds and removes sole lines that contain the pattern you've shown.

Code: Select all

[feyd@home]>php -r "$str = '  [edit?titles=asdfasdjfjfjfjfj]  jfjfjf]  ' . PHP_EOL . 'j [edit?titles=asdffff]' . PHP_EOL; echo preg_replace('#^\s*\[edit\?titles=.*\]\s*$#im', '', $str);"

j [edit?titles=asdffff]

Posted: Thu Aug 17, 2006 4:20 pm
by AndrewBacca
cheers feyd I put it in the wrong function :)

Thanks :D

Posted: Thu Aug 17, 2006 4:33 pm
by AndrewBacca
me again!

say I had

Code: Select all

blah[!EDIT]blah
how can I make it ignore the blah's either side so the [!EDIT] is removed but they stay, because at the moment the [!EDIT] is not getting removed at all when there is items touching it.

Ta

Posted: Thu Aug 17, 2006 4:56 pm
by feyd
change the "m" at the end of the pattern to an "s", add a "?" after .*, remove the "^" and "$" from the beginning and end respectively.

Posted: Fri Aug 18, 2006 2:48 am
by AndrewBacca
thats the tickets thanks alot