PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Clean-up a long string contents ... Posted by shamilsons on 30 May 2010 at 11:37 PM
Hello everyone,
I tried to clean-up some html tags(i.e. <font ...>, </font>, <img ...>, <b> etc) and just leave <tr><td>Expresions</td></tr> expressions for the given string below.

<tr><td>ISSN:</b></td><td bgcolor="#eeeeee" valign=top halign=left width="70%"><font face="Tahoma, Arial, Helvetica, sans-serif" size="-1">1097-6353</td></tr><tr align=left><td valign=top width="25%" ><font face="Tahoma, Arial, Helvetica, sans-serif" size="-1"><b>Title:</b></td><td valign=top width="70%" ><font face="Tahoma, Arial, Helvetica, sans-serif" size="-1"><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr align=left><td width="60%" valign=top><font face="Tahoma, Arial, Helvetica, sans-serif" size="-1">A-E-C Systems</font></td><td width="40%" align=right valign=top><font face="Tahoma, Arial, Helvetica, sans-serif" size="-2"><a href="#AdditionalTitleInfo"><img src="/ulrichsweb/images/fullCitation/tri_arrow_down.gif" width=11 height=6 border=0 alt="Additional Title Information" vspace=0 hspace=10>Additional Title Information</a></font></td></tr></table>


I tried several way with regular expressions but could not succeed.
Any help will be apperciated ...
thank you.


Report
This post has been deleted. Posted by acetechcn on 31 May 2010 at 11:49 PM
This post has been deleted.
Report
Re: Clean-up a long string contents ... Posted by CJNimes on 6 Jun 2010 at 5:55 PM
Maybe this works:

$search = "%(<[A-Za-z]+)(.*?)(>)%is";
$replace = "\\1\\3";
$newString = preg_replace($search,$replace, $oldString);
Report
Re: Clean-up a long string contents ... Posted by nuo on 23 Jun 2010 at 3:40 PM
Why not just use the strip_tags function?

$oldString ='<tr><td>ISSN:</b></td><td bgcolor="#eeeeee" valign=top halign=left width="70%"><font face="Tahoma, Arial, Helvetica, sans-serif" size="-1">1097-6353</td></tr>';

$newString = strip_tags($oldString, '<tr><td>');

echo $oldString . "\n";
echo $newString;




Report
Re: Clean-up a long string contents ... Posted by CJNimes on 24 Jun 2010 at 6:03 AM
I think he wants to clean styles also and strip_tags don't work for that.

If you have something like "<td style='xxx'><font>hello</font></td>" with strip_tags will result "<td style='xxx'>hello</td>" and I guess he wants to get "<td>hello</td>".



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.