close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

removing a tag

Thread began 2/05/2016 10:43 am by Jamie | Last modified 2/15/2016 3:09 pm by Ray Borduin | 443 views | 7 replies |

Jamie

removing a tag

Hey Ray

If I wanted to remove the styling soemthing like this: <strong style="line-height: 25.6px;"></strong>

how would I modify

<?php
function convertString($string) {
$retStr = $string;
$retStr = str_replace(array("<br />","<br>","<p>","</p>","<h1>","</h1>","<h2>","</h2>","<blockquote>","</blockquote>","<strong>","</strong>","<em>","</em>","<u>","</u>","&nbsp;"), "", $retStr);
$retStr = preg_replace("/\<a(.*)\>(.*)\<\/a\>/iU", "$2", $retStr);
$retStr = preg_replace("/\<span(.*)\>(.*)\<\/span\>/iU", "$2", $retStr);
$retStr = preg_replace("/\<u(.*)\>(.*)\<\/u\>/iU", "$2", $retStr);
$retStr = preg_replace("/\<h1(.*)\>(.*)\<\/h1\>/iU", "$2", $retStr);
$retStr = preg_replace("/\<strong(.*)\>(.*)\<\/strong\>/iU", "$2", $retStr);
$retStr = preg_replace("/<img[^>]+\>/i", " ", $retStr);
$retStr = preg_replace("/<h1[^>]+\>/i", " ", $retStr);
$retStr = preg_replace("/<h2[^>]+\>/i", " ", $retStr);
$retStr = preg_replace("/<h3[^>]+\>/i", " ", $retStr);
$retStr = preg_replace("/<p[^>]+\>/i", " ", $retStr);
return $retStr;
}
?>



As you can see I have $retStr = preg_replace("/\<strong(.*)\>(.*)\<\/strong\>/iU", "$2", $retStr); but it isnt removing the the tag

cheers

Jamie

Sign in to reply to this post

Ray BorduinWebAssist

The issue is that you are removing the "</strong>" tag above in the str_replace, so the preg_replace() won't work because it depends on both the open and close tags to be found before it removes them.

You could try moving the str_replace() to the end like:

php:
<?php

function convertString($string) {
    
$retStr $string;
    
$retStr preg_replace("/\<a(.*)\>(.*)\<\/a\>/iU""$2"$retStr);
        
$retStr preg_replace("/\<span(.*)\>(.*)\<\/span\>/iU""$2"$retStr);
        
$retStr preg_replace("/\<u(.*)\>(.*)\<\/u\>/iU""$2"$retStr);
        
$retStr preg_replace("/\<h1(.*)\>(.*)\<\/h1\>/iU""$2"$retStr);
        
$retStr preg_replace("/\<strong(.*)\>(.*)\<\/strong\>/iU""$2"$retStr);
    
$retStr preg_replace("/<img[^>]+\>/i"" "$retStr);
        
$retStr preg_replace("/<h1[^>]+\>/i"" "$retStr);
        
$retStr preg_replace("/<h2[^>]+\>/i"" "$retStr);
        
$retStr preg_replace("/<h3[^>]+\>/i"" "$retStr);
        
$retStr preg_replace("/<p[^>]+\>/i"" "$retStr);
    
$retStr str_replace(array("<br />","<br>","<p>","</p>","<h1>","</h1>","<h2>","</h2>","<blockquote>","</blockquote>","<strong>","</strong>","<em>","</em>","<u>","</u>","&nbsp;"), ""$retStr);
    return 
$retStr;
}
?>



That may work, but I'd suggest using the built in php function strip_tags() instead of this one.

Sign in to reply to this post

Jamie

gotcha. thanks

Jamie

Sign in to reply to this post

Jamie

I've seen that you can exclude some tags from the strip_tags function (eg $content=strip_tags($content,"<b><strong><em><i><p><br><ul><li><ol>");) but unsure how to incorporate that into <?php echo strip_tags($Noticeboard->getColumnVal("NoticeboardContent")); ?>

I am am wanting to strip all tags except <a href>....

Sign in to reply to this post

Ray BorduinWebAssist

<?php echo strip_tags($Noticeboard->getColumnVal("NoticeboardContent"),"<a>"); ?>

Sign in to reply to this post

Jamie

brilliant thanks...and am assuming that if you wanted other tags to be excluded you just add them with a comma separting? eg ("NoticeboardContent"),"<a>","<br>"); ?>

Sign in to reply to this post

Ray BorduinWebAssist

It looks like you add them right together without commas like "<a><br>"

Sign in to reply to this post

Jamie

thanks Ray

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...