chrisran Posted December 9, 2010 Share Posted December 9, 2010 Hi ! I've got a very long text like this: $var = "Blabla text text text [...] bla bla text text some weird text NEWCU - NEW Customer 0 -> 1 <br /> AMWHA - Some Description 0 -> 2 <br /> INST3 - Install Services 1 <br /> MORES - More Services 0 -> 1 <br /> bla bla bla text text text"; In my script I now have these keywords (NEWCU, AMWHA, MORES) set to 0 by default: $newcu = 0; $amwha = 0; $mores = 0; Now I'd like to set them to the value after the corresponding -> so for example NEWCU gets 1, AMWHA gets 2 and MORES gets 1. How do I preg_match that ? $newcu = preg_match("/NEWCU - [^] (.?) -> (.?)/",$var); <-- does not work. I'd like to grep on "NEWCU -" then skip everything until the -> and put the first digit before -> (here 0) into $newcu[1] and the digit after -> into $newcu[2].. Anyone an idea ? Thanks Quote Link to comment Share on other sites More sharing options...
mikecampbell Posted December 9, 2010 Share Posted December 9, 2010 $newcu = preg_match("/NEWCU - [^0-9]*([0-9]+) -> ([0-9]+)/",$var, $matches); $first = $matches[1]; $second = $matches[2]; Quote Link to comment Share on other sites More sharing options...
chrisran Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks for your reply mike, but it does not work this way: I wrote a small testprogram to check: $string = "NEWCU - Cust No 331351 0 -> 1"; $newcu = preg_match("/NEWCU - [^0-9]*([0-9]+) -> ([0-9]+)/",$string, $matches); $first = $matches[1]; $second = $matches[2]; echo "<BR><BR>NEWCU: $newcu ] $first -> $second<BR><BR>"; Result: NEWCU: 0 ] -> Any Idea ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.