Page 1 of 1

Regular Expressions and Preg_Replace

Posted: Wed Sep 20, 2006 11:34 am
by cfytable
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a function that returns the following multi-line string, with HTML tags included in the string (b/c the error is meant for display on an HTML page):

Code: Select all

<br />
<b>Warning</b>:  curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in <b>/serverinfo/nusoap.php</b> on line <b>xxxx</b><br />
<br />
<b>Warning</b>:  curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in <b>/serverinfo/nusoap.php</b> on line <b>xxxx</b><br />
mypassword
I want to parse out everything before "mypassword" so that my final modified string is just "mypassword".

My thought was to use regular expressions to replace (in English)
<br />everything<br /><br />everything<br /> with ""

I am having problems forming the pattern, possibly b/c of the newline spaces within the initial string, possibly just out of bad PHP syntax. Can anyone point me to what I'm doing wrong? Here is my current attempt at a PHP/RegEx combination:

Code: Select all

$password = [what function returns]
$password = preg_replace("<br />(.*)<br />\s<br />(.*)<br />\s/s", "", $password);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Sep 20, 2006 11:46 am
by n00b Saibot
what do plan to do with it

Posted: Wed Sep 20, 2006 11:59 am
by cfytable
I use the password as part of a form-based auto-login. So I need to strip out all the other error message text (which comes from a web service) and get access to just the password portion of that string.