php - Get anchor tag text using javascript - Stack Overflow

I don't know if it is possible! Maybe my thought is also wrong.I want to invoke a search corresp

I don't know if it is possible! Maybe my thought is also wrong. I want to invoke a search corresponding to all links in my Wordpress blog.

I am using an Ajax call for my other search in this site. How can I retrieve a linking text from hypertext tag in html. eg: <a href='www.example'>demo</a>.here i want to get 'demo' as input.

Thanks.

I don't know if it is possible! Maybe my thought is also wrong. I want to invoke a search corresponding to all links in my Wordpress blog.

I am using an Ajax call for my other search in this site. How can I retrieve a linking text from hypertext tag in html. eg: <a href='www.example.'>demo</a>.here i want to get 'demo' as input.

Thanks.

Share Improve this question edited Jul 13, 2010 at 6:07 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Jul 13, 2010 at 5:56 AadiAadi 7,10928 gold badges102 silver badges148 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

Try this:

var links_html_list = [];

var links = document.getElementsByTagName('a');

for(var l in links) {
   if(typeof links[i] == undefined) continue;
   links_html_list.push(links[i].innerHTML);
}

function search(term) {
   var results = [];
   for(var l in links_html_list) {
       var cur = links_html_list[l];
       if(typeof cur == undefined) continue; 
       if(cur.indexOf(term) != -1) results.push(cur);
   }
   return (results.length > 0) ? results : null;
}

What the search function does is it loops through the list of strings and if any have the term in it (indexOf), then it will get pushed into an array which is then returned. If there are no matches, it will return null.

You could use

$homePageText = file_get_contents(file.html);
preg_match_all('/<a .*?>(.*?)<\/a>/',$homePageText,$matches);

Then all anchor text elements will be stored in the array $matches.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745286602a4620599.html

相关推荐

  • php - Get anchor tag text using javascript - Stack Overflow

    I don't know if it is possible! Maybe my thought is also wrong.I want to invoke a search corresp

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信