Solved

Remove «  and    from text in php

Posted on 2016-08-05
4
110 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 110

Expert Comment

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

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41744812
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
ID: 41744830
Thanks Ray
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41744992
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 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