TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-08-2007, 11:53 PM   #1 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default URL to Match

I want to match this:

Code:
<i>-- http://www.<b>google</b>.<b>com</b>/ &nbsp; <a href="http://dmoz.org/Computers/Internet/Searching/Search_Engines/Google/">Computers: Internet: Searching: Search Engines: Google</a></i>
Through the domain part: http://www.<b>google</b>.<b>com</b>/ and get back the following part:

Code:
<a href="http://dmoz.org/Computers/Internet/Searching/Search_Engines/Google/">Computers: Internet: Searching: Search Engines: Google</a>
Currently using the following in my function:

Where $szSiteName == 'google'

PHP Code:
            $szURLToMatch 'http:\/\/www.\<b\>'    .    $szSiteName    .    '\<\/b\>.\<b\>com\<\/b\>';
            
preg_match("/\<i\>-- $szURLToMatch\/ &nbsp; (.*?) \<\/i\>/"$szGetContents$aMatches); 
But the array returns no match.

Whole code: http://talkphp.pastebin.com/d10b3a5e3

Last edited by Haris : 11-09-2007 at 12:27 AM.
Haris is offline  
Reply With Quote
Old 11-09-2007, 01:43 AM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

http://talkphp.pastebin.com/pastebin.php?diff=m457600c7

Basically I modified how the RegExp pattern is constructed. :)
Salathe is offline  
Reply With Quote
Old 11-09-2007, 01:52 AM   #3 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Improved working version: http://talkphp.pastebin.com/d67d9837f

Apart from that, how do I make a word optional?

PHP Code:
        preg_match('/of (about)? \<b\>(.*?)\<\/b\>/',$szGetContents$aMatches); 
How do I make about optional? :confused:
Haris is offline  
Reply With Quote
Old 11-09-2007, 02:36 AM   #4 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

As far as i can tell, you are already making "about" optional, if you add brackets around "of", followed by a ? it should have the same effect....

Code:
preg_match('/(of)?\s*?(about)?\s*?\<b\>(.*?)\<\/b\>/',$szGetContents, $aMatches);
I also added a non-greedy space matcher aswell, to take account for the spaces.
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 11-09-2007, 09:54 AM   #5 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by bluesaga View Post
As far as i can tell, you are already making "about" optional, if you add brackets around "of", followed by a ? it should have the same effect....

Code:
preg_match('/(of)?\s*?(about)?\s*?\<b\>(.*?)\<\/b\>/',$szGetContents, $aMatches);
I also added a non-greedy space matcher aswell, to take account for the spaces.
Of is not optional and it still doesn't work.

PHP Code:
preg_match('/ of (about)?\s*?<b\>(.*?)\<\/b\>/',$szGetContents$aMatches); 
Full code: http://talkphp.pastebin.com/d55d44b38

Where $this->szURL == www.lost-series.com
Haris is offline  
Reply With Quote
Old 11-09-2007, 09:59 AM   #6 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by Haris View Post
Of is not optional and it still doesn't work.

PHP Code:
preg_match('/ of (about)?\s*?<b\>(.*?)\<\/b\>/',$szGetContents$aMatches); 
Full code: http://talkphp.pastebin.com/d55d44b38

Where $this->szURL == www.lost-series.com
Edit:

This works:

PHP Code:
preg_match('/ of( about)? <b\>(.*?)\<\/b\>/',$szGetContents$aMatches); 
Haris is offline  
Reply With Quote
Old 11-13-2007, 09:56 AM   #7 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

Meaning, the space that comes with the "about" is also optional (which would make sense not to have two spaces). Sorry i couldn't of been of more help :)
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:17 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design