-5

I have that text:

$text = 'Some text... <a href="http://foo.bar/***">Read More</a>';

I need to remove this: <a href="http://foo.bar/***">Read More</a>. *** is unknown word.

6
  • how about to just cut your spring till encountering the first < ? Your test string is quite simple Commented May 2, 2017 at 12:06
  • do you want like this:- eval.in/785463 Commented May 2, 2017 at 12:07
  • @RomanPerekhrest ok, but how to do that? i am noob in php) Commented May 2, 2017 at 12:07
  • @AlivetoDie Thanks so much! Commented May 2, 2017 at 12:09
  • Handling markup texts with text tools is not a trivial job. You should use the XML parser. php.net/manual/en/book.xml.php To ask a useful question, at first you should define, what is an "unknown word". This sounds like a whitelist. Commented May 2, 2017 at 12:14

2 Answers 2

0

Just use strip_tags function

<?php 

$text = 'Some text... <a href="http://foo.bar/***">Read More</a>';
$text =strip_tags($text);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

That's the way to go stripping tags by builtin. However, I think this is not what the questioner is looking for. As I understand, he seems to want removing entire tags only when they contain an "unknown word" - whatever this should be. Since he does not properly explain what he exactly means, I'll give you an UV for utilizing the built nevertheless. :)
0

You can easily try this function

<?php
str_replace(
  "The Unkown phrase  you want to remove  "   ,
  " The New Phrase eg.Space if you want to  " ,
  $yourText
);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.