Solved

Remove «  and    from text in php

Posted on 2016-08-05
4
39 Views
Last Modified: 2016-08-05
Hi;

I want to remove html tags and also tags like: «  /    /»  from text and get clean text,i use the function strip_tags() but this function cannot remove all of these tags,need a function that clean completely a text in php.

Thanks in advance
0
Comment
Question by:MOSTAGHASSI
  • 3
4 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
You can use str_replace() for this.  I'll try to show you an example in a minute.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
Try this.  You can add other things to the $unwanted array if you need to modify the replacement patterns.
https://iconoun.com/demo/temp_mosta.php
<?php // demo/temp_mosta.php
/**
 * https://www.experts-exchange.com/questions/28961805/Remove-laquo-and-nbsp-from-text-in-php.html
 *
 * http://php.net/manual/en/function.strip-tags.php
 * http://php.net/manual/en/function.str-replace.php
 */
error_reporting(E_ALL);


function tidy($str)
{
    $unwanted =
    [ '&laquo;'
    , '&nbsp;'
    , '&raquo;'
    ]
    ;

    $new = strip_tags($str);
    $new = str_replace($unwanted, '', $new);
    return $new;
}

$old = '<div>Foo&raquo;</div>';
$new = tidy($old);

echo htmlentities($old);
echo '<br>';
echo htmlentities($new);

Open in new window

0
 

Author Closing Comment

by:MOSTAGHASSI
Comment Utility
Thanks Ray
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
:-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now