HI all,
I'm using $content = str_ireplace($search, $replace, $var3); to search and replace value in $var3.
My problem is i want to take out all the table attribute found in $var3.
For example - <table with="100" height=""><tr><td class="cont" style="hsd">
-
<a href="test.php">content</a>
-
</td></tr></table>
I only want to echo the link content without the table structure at all.
Is there any pattern to search all the table attribute and replace with null value?
I got a long string from database to remove the table structure, very appreciate your kind help. Thanks in advance.
Regards,myza.
7 7390
Hey, Nurmaiza.
I've added [code] tags to your post to format the code you posted. Please do make a note to do this when you're posting code.
Thanks.
Hi,
Regular expressions are probably the best way to go with this but here's an alternative using some of the many string manipulation functions built into PHP: -
$var_start ='<table with="100" height=""><tr><td class="cont" style="hsd"><a href="test.php">content</a></td></tr></table>' ;
-
-
$lnStartPos = strpos($var_start, '<a href') ;
-
$lnEndPos = strpos($var_start, '</a>') ;
-
-
$var_end = substr($var_start, $lnStartPos, $lnEndPos) ;
-
echo $var_end;
-
I hope that helps
nathj
Hi,
Thank you nathj, I've tried the code and resulting content with link to display. Now the content display partially. I got long string, my intention is to remove the table structure, only echo the wording as well as the link. Someone will post the content everyday, and this program will remove its table format and style. -
$var_start ="<table border='0' cellpadding='0' class='sub' bgcolor='#f0f0f0'> <tbody> <tr> <td colspan='3' valign='top' style='text-align: left'><img src='images/stories/2008aug2/0908bc01-aug9.jpg' border='0' /></td> </tr> <tr style='text-align: left'> <td colspan='3' valign='top' style='text-align: left'> <p>File picture of Zulkifli Nordin (extreme right) at the Bar Council meeting.</p> </td> </tr> <tr style='text-align: left'> <td width='70%' valign='top' style='text-align: left'> <a href='http://localhost/mversion2/articles.php?id=7805'>Zul Nordin resurfaces unrepentant</a></span> <p><span style='font-size: small'>PARLIAMENT, Aug 18 - PKR MP Zulkifli Nordin today emerged from hiding â€- unrepentant and defiant over his role in the fracas at the Bar Councilâ€>s forum on conversion and Islam on August 9. Indeed, he was in a fighting mood and said that he was considering proposing a motion in Parliament to sanction the Bar Council for its anti-Islam stand.</span></p> <p>
-
<a href='http://localhost/mversion2/articles.php?id=7805'>Read More </a></p> </td><td valign='top' style='text-align: left'> </td> <td width='30%' valign='top' style='text-align: left'> <ul> <li> <p><a href='http://localhost/mversion2/articles.php?id=7783'>Zeti: Asia to continue facing inflationary pressure</a></p> </li> </ul> <ul> <li> <p><a class='contentpagetitle' href='http://localhost/mversion2/articles.php?id=7784'> Accuserâ's Quran vow makes it<br />tougher for Anwar</a></p> </li> </ul> <ul> <li> <p><a class='contentpagetitle' href='http://localhost/mversion2/articles.php?id=7793'> Thunderâ rumbles past 
Dark Knightâ with US$26m</a></p> </li> </ul> <ul> <li> <p><a class='contentpagetitle' href='http://localhost/mversion2/articles.php?id=7800'> Commodities flash a signal of <br />global relief</a></p> </li> </ul> </td> </tr> </tbody> </table>";
-
-
$Start = strpos($var_start, '<a href') ;
-
$End = strpos($var_start, '</a>') ;
-
-
$var_end = substr($var_start, $Start, $End) ;
-
echo $var_end;
-
Really need your advise. Thanks in advance for your time and kind help.
p/s: Noted Markus.
Regards, myza.
Hi,
Regular expressions are probably the best way to go with this but here's an alternative using some of the many string manipulation functions built into PHP: -
$var_start ='<table with="100" height=""><tr><td class="cont" style="hsd"><a href="test.php">content</a></td></tr></table>' ;
-
-
$lnStartPos = strpos($var_start, '<a href') ;
-
$lnEndPos = strpos($var_start, '</a>') ;
-
-
$var_end = substr($var_start, $lnStartPos, $lnEndPos) ;
-
echo $var_end;
-
I hope that helps
nathj
Ok, you need to get the full <a> tag not just the text in the middle. This shouldn't be too difficult you just need to play around with the value of the start position.
Try experimenting with that value, adjusting it and seeing what comes out using the code snippet I originally posted. It's also worth reading up on the string manipulation functions within php.
Have a play and honestly it will come right you just need to mess around with the code sample a bit. By doing this you will also gain a better understanding of how these functions work and what they are doing which means you will be able to use them more effectively in the future and be able to maintain this code more efficiently.
Cheers
nathj
I tried to play around...its already 3 days trying the same things.I know its easy but I found table structure/attribute is hard to remove.
I tried to play around...its already 3 days trying the same things.I know its easy but I found table structure/attribute is hard to remove.
The original code is getting out the full link. However, when you echo that variable it prints it as a link. So the code I gave you does what you need, I think. What you do with the variable after that is another matter. The variable itself will contain the full <a> tag for you.
Run the code and view the source to check it out.
Cheers
nathj
PS Sorry about the earlier confusion - I was pretty tired when I replied and not really thinking straight
Sign in to post your reply or Sign up for a free account.
Similar topics
by: disaia |
last post by:
2 problems:
Example: If a person types in a part number into Yahoo:
1. Is there a way for Yahoo to list your web site as one of the
results.
2. If the user clicks on your link, can your web...
|
by: Axel |
last post by:
Is it possible to write a Stored Procedure that takes a string of
search keywords as argument and returns the recordset? At the mo I am
passing the WHERE String as argument.
I got this...
|
by: Phlip |
last post by:
C++ers:
Here's an open ended STL question. What's the smarmiest most templated way
to use <string>, <algorithms> etc. to turn this:
" able search baker search charlie "
into this:
" able...
|
by: harhaiko |
last post by:
Hello, I have 4,4 million rows of data in one column. I want to search
for a string in each line. There are random amount of characters
before the string I want to find. The string starts with the...
|
by: Christopher Koh |
last post by:
I will make a form which will search the database (just like google
interface) that will look/match for the exact name in the records of a
given fieldname. Any suggestions on how to make the code?
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the
code to get the values from the database and...
|
by: Martien van Wanrooij |
last post by:
I have been using phpdig in some websites but now I stored a lot of larger
texts into a mysql database. In the phpdig search engine, when you entered a
search word, the page where the search word...
|
by: Eric |
last post by:
Hi: I have two files. I search pattern ":" from emails text file and
save email contents into a database. Another search pattern " field is blank. Please try again.",
vbExclamation + vbOKOnly...
|
by: kanley |
last post by:
I have a main table with a text description field. In this field, its
populated with a string of data. I need to identify from this string
of data the name of the vendor using some keywords.
I...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |