User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,993 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,798 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 426 | Replies: 8
Reply
Join Date: Dec 2007
Posts: 9
Reputation: kusal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kusal kusal is offline Offline
Newbie Poster

Regex problem in PHP

  #1  
Dec 5th, 2007
Hi, hope this is the right place,

Here is my problem

<h4 Bla Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla Bla
Bla Bla Bla Bla </h4>

I want the content between <h4> tags in a variable, using only one expressions

thnx
Kusal
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Regex problem in PHP

  #2  
Dec 5th, 2007
you can try this one:

  1. $reg = '/<h4>(.+)<\/h4>/';

hope this helps.
Last edited by ryan_vietnow : Dec 5th, 2007 at 2:23 am.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Regex problem in PHP

  #3  
Dec 5th, 2007
Using ryan_vietnow's pattern, you can get the string between <h4> and </h4>.
  1. <?php
  2. $x="<h4>blah blah blah</h4>";
  3. $reg = '/<h4>(.+)<\/h4>/';
  4. preg_match($reg,$x,$matches);
  5. print $matches[0];
  6. ?>

If you wanna learn more bout regular expression, Here is the video tutorial.

P.S. ryan_vietnow, thanks. I was scratching my head over the same thing for sometime now !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 9
Reputation: kusal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kusal kusal is offline Offline
Newbie Poster

Re: Regex problem in PHP

  #4  
Dec 5th, 2007
No this works only for one line I need to get content in multiple lines, as I given in the example.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Regex problem in PHP

  #5  
Dec 5th, 2007
Originally Posted by kusal View Post
<h4 Bla Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla
Bla Bla Bla Bla Bla Bla
Bla Bla Bla Bla </h4>


Aren't you saving this in a variable or something ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 9
Reputation: kusal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kusal kusal is offline Offline
Newbie Poster

Re: Regex problem in PHP

  #6  
Dec 5th, 2007
<h4><font color="#FFFF00">CALVARY BAPTIST CHURCH, 334-585-6455<br>
310 DOTHAN ROAD, ABBEVILLE AL 36310</font></h4>

this is a sample what i want,

$data = file_get_contents($url);
all is in $data
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Regex problem in PHP

  #7  
Dec 5th, 2007
  1. <?php
  2. $reg = '/<h4>(.*)<\/h4>/s';
  3. $data="<h4><font color=\"#FFFF00\">CALVARY BAPTIST CHURCH, 334-585-6455<br>
  4. 310 DOTHAN ROAD, ABBEVILLE AL 36310</font></h4>";
  5. preg_match($reg,$data,$matches);
  6. print $matches[1];
  7. ?>

Phew! finally. I hope this works.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 9
Reputation: kusal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kusal kusal is offline Offline
Newbie Poster

Re: Regex problem in PHP

  #8  
Dec 5th, 2007
Hey thnx!!!! it works, thnx
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Regex problem in PHP

  #9  
Dec 5th, 2007
you are welcome!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC