Current location: Hot Scripts Forums » Programming Languages » PHP » How to Get the Anchor Text of a Link


How to Get the Anchor Text of a Link

Reply
  #1 (permalink)  
Old 05-29-07, 07:57 PM
jmahmud jmahmud is offline
New Member
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to Get the Anchor Text of a Link

Hi
I have a Web page with a single link, I want that when I click the link, it goes to a PhP Script.

So I have set


<a href="test.php"> Object </a>


Now how can I get the text "Object" in my PhP Script ?

In general, I know that PhP script can get the form elements, when a form is submitted. But My problem is different. The link is not a formelement.

How to get the text of the link ?

Any help/suggestions will be appreciated.

thanks

jalal.
Reply With Quote
  #2 (permalink)  
Old 05-29-07, 08:06 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You would also need to pass it as a GET parameter on the end of the URL -
Code:
<a href="test.php?obj=Object"> Object </a>
Then in your test.php, reference it like this -
PHP Code:

echo $_GET['obj']; 

__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 05-29-07, 08:56 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
You could do this with preg_match() and the following RegExp:
PHP Code:

<?php


$contents 
file_get_contents'page.html' );

preg_match'/<a[^>]+>([^<]+)<\/a>/si'$contents$m );

$link_text trim$m[1] );

?>
__________________
The toxic ZCE
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Club2Share.com - Link exchange with Active Site 20000+ Members Club2share.com Traffic Exchange 1 12-20-06 10:17 PM
Link Exchange Management linkmore General Advertisements 0 11-23-05 08:38 AM
Six Sites Exchanging Links! - PR3+ Web Hosting, Web Design, Entertainment & Career coffeecoder General Advertisements 0 10-10-05 12:52 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM
I'm confused..plz help Brittany23 CSS 5 05-24-05 11:52 AM


All times are GMT -5. The time now is 06:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.