Jump to content


Photo

search for text in html body using javascript?


  • Please log in to reply
6 replies to this topic

#1 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 09 October 2006 - 09:40 AM

how can i search for html body for text in <p>hi h r u?</p> tags or in <b>hello world</b>

e.g
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
aaaaa<p>hi h r u?</p>bbbbbbbbbbbbbb<b>hello world</b>ccccccc
</body>
</html>

i need only "hello world" or "hi h r u?"
please help me

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 03:53 PM

Regular expressions?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 11 October 2006 - 04:43 AM

please can give me a example?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 October 2006 - 10:55 PM

document.body.innerText.match( /hello world/ )

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 16 October 2006 - 10:43 AM

okey but if i want to get only text in a body which contains bold tag e.g
<b>Hello World</b>
Or
<b class='something'>Hello World</b>
Or
<b><span class='somthing'>Hello World</span></b>
anyother text contains bold or having strong tag
i want to search for only this please tell me how and also please help me where i can found more detail about RegExp();
thanks a lot.


#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 October 2006 - 11:33 AM

here is a nice reference for regular expressions

Good Luck,
TOm

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 October 2006 - 02:38 PM

If you want to actually parse HTML, you'll have to write/find a parser.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users