Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 28th, 2011, 08:26 AM
pedroz pedroz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 112 pedroz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 59 m 45 sec
Reputation Power: 9
PHP-General - Regular expression

PHP Code:
 $link_text 'Apply now';
                                
$content '<td align="right" class="apply">   <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>';
                

$pattern '|<a[^>]+>('.$link_text.')</[^>]+>|U';   
preg_match($pattern$content$output); 

                
$pattern '/<[a]{1}(.*)?>(.*)<\/[a]{1}>/';  
$content trim(preg_replace($pattern'$1'$output[0])); 

... 
// then parse $content to get the href url 



Is it possible to know what is wrong with the regular expression to get the href of this tag?
<td align="right" class="apply"> <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>

Not getting anything in $output. I've this code working for a similar <a ..> tag.

Thanks!

Reply With Quote
  #2  
Old September 28th, 2011, 08:38 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,809 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 18 h 6 m 48 sec
Reputation Power: 6112
Your match text has "now" but the link has "Now"
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #3  
Old September 28th, 2011, 04:35 PM
chris0 chris0 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 30 chris0 User rank is Lance Corporal (50 - 100 Reputation Level)chris0 User rank is Lance Corporal (50 - 100 Reputation Level)chris0 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 h 1 m 46 sec
Reputation Power: 2
regex patterns must start with '/' and ends with '/' , and after the last '/' add an 'i' to make case insenstive

$pattern = '/regex/i'

Reply With Quote
  #4  
Old September 28th, 2011, 04:39 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,710 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 6 h 44 m 28 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by chris0
regex patterns must start with '/' and ends with '/'

Not necessarily.

Reply With Quote
  #5  
Old September 28th, 2011, 04:49 PM
chris0 chris0 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 30 chris0 User rank is Lance Corporal (50 - 100 Reputation Level)chris0 User rank is Lance Corporal (50 - 100 Reputation Level)chris0 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 h 1 m 46 sec
Reputation Power: 2
Quote:
Originally Posted by requinix
Not necessarily.

yes you are right, its however appears to be the standered and better for script consistency imo

still though, the i modifier should make it case insensitive

Reply With Quote
  #6  
Old September 28th, 2011, 05:45 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,809 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 18 h 6 m 48 sec
Reputation Power: 6112
Quote:
Originally Posted by chris0
yes you are right, its however appears to be the standered and better for script consistency imo
Unless of course the pattern contains a / (which this one did), which would force you to escape the / if it's in the pattern, leading to patterns that contain \/ everywhere, which are harder to read than if you had chosen a new delimiter.

Reply With Quote
  #7  
Old October 3rd, 2011, 10:30 AM
jvihavainen jvihavainen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 19 jvihavainen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 31 m 26 sec
Reputation Power: 0
Send a message via AIM to jvihavainen Send a message via MSN to jvihavainen
This should do the trick.

PHP Code:
<?php

$content 
'<td align="right" class="apply">   <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>';

preg_match('#<a href="(.+)" onClick=".+" title=".+">Apply Now</a>#U'$content$output);
var_dump($output);

?>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > PHP-General - Grabbing link href [was "Regular expression" in PHP]

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap