473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to perg_match between <tr>and </tr> or <td>ot</td> in php

7
I want to match some particular text between <tr>and </tr> or <td>and </td>....
in PHP.

like below............
<table><tr>
CATEGORY:
<td><font face="Verdana" size="1" color="#A000A0">
Wedding

Accessories
</font></td>
<td><font face="Verdana" size="1" color="#A000A0">
Wedding

Crèche
</font></td>
<td>
<font face="Verdana" size="1" color="#A000A0">
Wedding

Gifts
</font></td>


<table>
<tr>
WORLDWIDE:

FOR INTERNATIONAL SUPPLIERS CLICK HERE
<td><font face="Verdana" size="2" color="#A000A0"><b>
Australia<b/>
</font></td> <td><font face="Verdana" size="2" color="#A000A0"><b>Granada Malta</b></font></td>


BUT Want to match only category table(categories have same font style ,face ,size and color).

and also want to match internation suppliers(pls look countries have <b></b>tags between <font></font> tags
Nov 22 '06 #1
5 2919
I don't know of a direct way other than a string comparision.
[PHP]
$start = strpos($str, "string"); // use this to get right before the first tag
$start = strpos($str, "string", $start); //(optional) use this to get right before the first tag if the line above only get to two tags before, use as many as neccessary
$start = strpos($str, "<td>", $start) + 4;
$end = strpos($str, "</td>", $start) ;
$length = $end - $start;
$contents = substr($str, $start, $length);
[/PHP]

It's a little crude, but works.
Nov 22 '06 #2
steven
143 100+
Sorry, do I understand that you want the text between the tags?

The the expression should be something along the lines of...

preg_match("/<td>(.*?)<\/td>/", $stringToSearch, $matches);

This will capture all the text between the <td></td> tags. It will be in matches[1].

You would need to read the html file into a string, using file_get_contents(). You could run a regular expression to capture just the table you want. But you should change your HTML, place the table titles in the <caption> tag, then you can modify the expression above to capture between caption tags.
Nov 23 '06 #3
mahesr
7
hi all,


thanks,but not work.i want to a text like

Wedding
Accessories

Wedding
Crèche

only Between Category tr's or td's..pls look this have <font> tags...so easy to match using this font but do not know the code...
Nov 23 '06 #4
after you get what in between the <td> / <tr> tag use
$contents = strip_tags($contents);
This does exactly what it sounds like, it strips all tags so everything between a < and a > goes away, all of them. You can also chose to keep certain ones. For futher reference: http://us3.php.net/strip_tags.
Cheers,
Happy Thanksgiving
Nov 23 '06 #5
after you get what in between the <td> / <tr> tag use
$contents = strip_tags($contents);
This does exactly what it sounds like, it strips all tags so everything between a < and a > goes away, all of them. You can also chose to keep certain ones. For futher reference: http://us3.php.net/strip_tags.
Cheers,

Happy Thanksgiving
hai try this code..i think this is working perfectly

preg_match_all('/\<tr\>(.*?)\<\/tr>/is', $content, $matches);
Nov 28 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Federico Moschini [328594] | last post by:
I have to make difference between2 data from a table in SQL. The page is made with Frontpage, and it extracts QtaGiaCons and Quantita from table "oclrighe". I have to make Quantita -...
7
by: James Johnson | last post by:
Are there structs in JavaScript? If not, what's the closest thing, or do I just use parallel arrays? I'm populating a JavaScript array from ColdFusion query, but I don't think I can do this: ...
2
plumpnation
by: plumpnation | last post by:
I have now got this bulky piece of script working, it reads the form correctly, which sends the request to the web service using SOAP. It conforms to their DTD and the web service then responds and...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.