Jump to content

[SOLVED] Anyone able to help on regex issue with my html source code...


jkrystof

Recommended Posts

If anyone can help out with preg_match_all or some guidance that would be greatly appreciated. I'm trying to pull some user info from my html which looks like below.

 

<div class="td user_ref">
<p class="alignright" id="user">
	<span class="Height">FT</span>
	<span><span class="user_ref" userid="jbk" mwformat=",2" userfield="height1">6.3</span>
	</span>
</p>
</div>

 

I am looking to pull only the 6.3 and place it into an array. I've displayed one div class but I will have between 20 to 30 html segments just like this in my complete html. Also, there are other div classes not equal to "td user_ref" within the html which should be ignored. I would like to extract each height and place it within the height array.

 

preg_match_all($string_pattern, $html, $height);

 

I've been attempting to learn the $string_pattern part with regular expressions but only getting constant headaches.

 

all help and thoughts appreciated..thanks

 

Link to comment
Share on other sites

Thanks, that worked for me. There was one issue I was still having on another segment within the html where I'm using regex too.

 

<div class="td user_ref">
   <p class="mweight" id="user_id"> Weight Value </p>
</div>

 

In this case I used the following regex and I don't know what to put in following the id=??????? because my user id is a numeric value greater than 1, i.e id="user1", "user2"..."user27".."user98" etc. Also I don't want to include the class="mweight" because that is the same in other <p></p> segments I'm not interested in.

 

I can return the first 9 if I use a /d but I don't know how to return for all numbers greater than or equal to 1.

 

 

preg_match_all('~<div.+?"td user_ref"[^>]*>.+?<p.+?id=???????[^>]*>(.*?)</p>~is',$html,$weight);

 

thanks for your help

Link to comment
Share on other sites

thanks, it does work but for some rreason I only get every other user_id entry saved to my $weight array. any thoughts why this would happen?

 

for example,

$weight[0]= "user2"

$weight[1]= "user4"

etc...

 

I'm using the following code

 

preg_match_all('~<div.+?"td user_ref"[^>]*>.+?<p.+?id="user\d+?"[^>]*>(.*?)</p>~is',$html,$weight);

 

the html is the same for each user,

 

<div class="td user_ref">
   <p class="mweight" id="user_id"> Weight Value </p>
</div>

 

Link to comment
Share on other sites

thanks crayon for your help. i played with it some this morning and got it to work now. im not exactly sure why it was skipping every other one but the following worked for me.

 

preg_match_all('~<div.+?class="td.+?"[^>]*>.+?<p.+?id=".+?height.+?"[^>]*>(.*?)</p>~is',$target2,$height);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.