Solved

Remove «  and    from text in php

Posted on 2016-08-05
4
55 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
ID: 41744804
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
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 108

Expert Comment

by:Ray Paseur
ID: 41744992
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change password links 7 74
Problem with Simple PHP/mySQL Query 3 51
WordPress Themes 10 34
How can I upload multiple images from a HTML form? 2 18
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to dynamically set the form action using jQuery.

867 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

16 Experts available now in Live!

Get 1:1 Help Now