Specialized Search requirement - need help figuring out

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!

Moderator: General Moderators

Post Reply
Vacman
Forum Newbie
Posts: 8
Joined: Fri Jan 22, 2010 7:13 pm

Specialized Search requirement - need help figuring out

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Specialized Search requirement - need help figuring out

Post by Christopher »

Check the documentation for preg_match(). There should be plenty of examples there.
(#10850)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Specialized Search requirement - need help figuring out

Post 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); 
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Specialized Search requirement - need help figuring out

Post by josh »

Vacman
Forum Newbie
Posts: 8
Joined: Fri Jan 22, 2010 7:13 pm

Re: Specialized Search requirement - need help figuring out

Post 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.
Post Reply