Solved

Remove «  and    from text in php

Posted on 2016-08-05
4
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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