Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php新手求助: 如何获取超链接的title值?

php新手求助: 如何获取超链接的title值?

Jun 23, 2016 pm 02:26 PM

本帖最后由 ileleX 于 2013-10-31 10:07:11 编辑

php 获取链接文字

如题。

如一个超链接:

超链接标题9

用 $_GET['title']可以获取" HypeLinkTitle",那如何获取" 超链接标题8"和" 超链接标题9"?

希望大虾能就这个超链接给点提示,谢谢!

回复讨论(解决方案)

通过js传输

超链接标题9


var _h = $('hplink').html();

然后呢?  初学php,望能详细点哈。

通过js传输
超链接标题9


var _h = $('hplink').html();

然后呢?  初学php,望能详细点哈。

$('#hplink').html();

$('#hplink').attr('title');


通过js传输
超链接标题9


var _h = $('hplink').html();

然后呢?  初学php,望能详细点哈。

<!DOCTYPE html><html>	<head></head>		<script type="text/javascript" src="jquery-1.7.1.min.js"></script>	<script type="text/javascript">		$(function (){			$('#xxxxx').click(function (){				var t = $(this).attr('title');				var h = $(this).html();				var r = $(this).attr('rel');				//字符串连接,				var u = r + '&testTitle='+ t + '&testHtml=' + h;				alert(u);			});		})	</script>	<body>		<a href="javascript:;" rel="http://www.example.com/?title=HypeLinkTitle" title="testTitle" id="xxxxx">testHtml</a>	</body></html>
Copy after login
Copy after login
Copy after login



通过js传输
超链接标题9


var _h = $('hplink').html();

然后呢? 初学php,望能详细点哈。

<!DOCTYPE html><html>	<head></head>		<script type="text/javascript" src="jquery-1.7.1.min.js"></script>	<script type="text/javascript">		$(function (){			$('#xxxxx').click(function (){				var t = $(this).attr('title');				var h = $(this).html();				var r = $(this).attr('rel');				//字符串连接,				var u = r + '&testTitle='+ t + '&testHtml=' + h;				alert(u);			});		})	</script>	<body>		<a href="javascript:;" rel="http://www.example.com/?title=HypeLinkTitle" title="testTitle" id="xxxxx">testHtml</a>	</body></html>
Copy after login
Copy after login
Copy after login


谢谢。也感谢 fire53。

获取这个我会啊,现在的问题是,我要如何把这取得的值传回到php?
想实现的作用是,点击这个链接,php后台就根据这个链接超本文从数据库读取相关的文章。
其他都弄好了,现在就差如何将获取的超文本传给php了。
链接的形式是
超链接标题8



通过js传输
超链接标题9


var _h = $('hplink').html();

然后呢? 初学php,望能详细点哈。

<!DOCTYPE html><html>	<head></head>		<script type="text/javascript" src="jquery-1.7.1.min.js"></script>	<script type="text/javascript">		$(function (){			$('#xxxxx').click(function (){				var t = $(this).attr('title');				var h = $(this).html();				var r = $(this).attr('rel');				//字符串连接,				var u = r + '&testTitle='+ t + '&testHtml=' + h;				alert(u);			});		})	</script>	<body>		<a href="javascript:;" rel="http://www.example.com/?title=HypeLinkTitle" title="testTitle" id="xxxxx">testHtml</a>	</body></html>
Copy after login
Copy after login
Copy after login


这种 onclick + rel 的形式,百度蜘蛛可以正常获取链接并爬过去么?

传回到php ?

$('#hplink').attr('title');

谢谢,如何将这值传给php呢?希望能详细点,谢谢!

传回到php ?
版主的阿大,是的。
想实现的作用是,点击这个链接,php后台就根据这个链接的超本文从数据库读取相关的文章。蜘蛛要能爬的到。

js获取到了,然后可以通过get或者post传回啊。。。


直接都放到问号后面不就行啦
http://www.example.com/?title=HypeLinkTitle__超链接标题8__超链接标题9__超链接标题100
get后再explode分割开来

$title_list = explode("__", $_GET['title']);
echo $title_list[0];
echo $title_list[1];
echo $title_list[100];


传回到php ?
版主的阿大,是的。
想实现的作用是,点击这个链接,php后台就根据这个链接的超本文从数据库读取相关的文章。蜘蛛要能爬的到。

你这是要动态取文章?  
用ajax把参数传后台处理,success方法里把返回的文章内容显示在页面上。这样蜘蛛是抓不到的啊。

js获取到了,然后可以通过get或者post传回啊。。。
应该就是这个办法,能就这个链接给点代码提示么?

你这是要动态取文章?  
用ajax把参数传后台处理,success方法里把返回的文章内容显示在页面上。这样蜘蛛是抓不到的啊。
蜘蛛抓不到就没用咯。谢谢

直接都放到问号后面不就行啦
http://www.example.com/?title=HypeLinkTitle__超链接标题8__超链接标题9__超链接标题100
get后再explode分割开来

$title_list = explode("__", $_GET['title']);
echo $title_list[0];
echo $title_list[1];
echo $title_list[100];



传回到php ?
版主的阿大,是的。
想实现的作用是,点击这个链接,php后台就根据这个链接的超本文从数据库读取相关的文章。蜘蛛要能爬的到。
这种方法是可以的,但问题是现在链接的形式就已经定死了。谢谢

PHP没法活的HTML页面上的元素值,只能通过$_GET,$_POST等获得form元素里的值。

这个只能通过第三方传输。

你可以先把这个文档放在文本框中,然后通过$(".标记类")获取,也可以通过js方法判断隐藏和显示不就行了么,为什么非要搞什么超链接》》

你可以先把这个文档放在文本框中,然后通过$(".标记类")获取,也可以通过js方法判断隐藏和显示不就行了么,为什么非要搞什么超链接》》
是一个web程序,不搞链接蜘蛛不好整呐,谢谢!

PHP没法活的HTML页面上的元素值,只能通过$_GET,$_POST等获得form元素里的值。

这个只能通过第三方传输。
嗯,谢谢。如果两个都是泼诶取泼呢?


PHP没法活的HTML页面上的元素值,只能通过$_GET,$_POST等获得form元素里的值。

这个只能通过第三方传输。
嗯,谢谢。如果两个都是泼诶取泼呢?

泼诶取泼? PHP?

我想了下,我回答错了

html的话,可以用curl抓取回来用正则匹配
php的话用可以用fopen, 去除多余的字符(空格换行之类的),再正则匹配。

不要要实现你这个想法,还是按楼上的

一下子全部放到dom里,用js切换dom的显示和隐藏就好了,这样蜘蛛也能抓得到

不要要实现你这个想法,还是按楼上的

一下子全部放到dom里,用js切换dom的显示和隐藏就好了,这样蜘蛛也能抓得到
嗯,谢谢。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? Apr 01, 2025 pm 03:09 PM

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...

See all articles