Page 1 of 1

Specialized Search requirement - need help figuring out

Posted: Fri Jan 22, 2010 7:24 pm
by Vacman
OK - Here is what I am trying to accomplish.

I have an html file on my server.
I have loaded the contents of that file into a variable called $contents.
I now want to look at that string and find each occurrence of a particular group of characters and extract that group of characters.

Example :
<a onclick='modal_maptile(539396,"null",745,745,"null","null",null,"null","null",null,24,"bcity","null",6,null,null,null);return false;
- What I want to do is extract everything that is between this >> maptile( and this >> );return false

The contents between will be different most of the time. but there will be about 100 of these onclick instances in the file/string.
Of course I want to dump each field (separated by the comma) into an array.

After I do this step, then there is more I will need to do, but this is where I am stuck right now.

Thanks!

Re: Specialized Search requirement - need help figuring out

Posted: Sat Jan 23, 2010 2:42 am
by Christopher
Check the documentation for preg_match(). There should be plenty of examples there.

Re: Specialized Search requirement - need help figuring out

Posted: Sat Jan 23, 2010 10:46 am
by AbraCadaver
This should do it for any onclick:

Code: Select all

preg_match_all('/onclick=[^\(]*\(([^\)]*)\)/i', $content, $matches);
If you want only the modal_maptile onclicks then:

Code: Select all

preg_match_all("/onclick='modal_maptile\(([^\)]*)\)/i", $content, $matches); 

Re: Specialized Search requirement - need help figuring out

Posted: Sat Jan 23, 2010 11:28 am
by josh

Re: Specialized Search requirement - need help figuring out

Posted: Sun Jan 24, 2010 4:56 pm
by Vacman
Great start folks! I do appreciate it.

BTW - I found this just this morning: http://www.webcheatsheet.com/php/regula ... ssions.php

I will try some of these and get back to you here and let you know where I am at.