2

I want to remove tag using array().

This's my code:

$string = '<span style="font-family: 'Angsana New', serif;">Hello</span>';
$search = array('/<span (.*?)\>(.*?)\<\/span\>/');
$replace = array('\\2');
echo preg_replace($search, $replace, $string);

This code isn't error. But It's not remove tag.

4
  • Do you want to remove entire html tags? else you can replace span tag into some other tags? Commented Aug 25, 2014 at 4:36
  • oh it is an error - and the syntax highlighting tells you exactly what it is. Commented Aug 25, 2014 at 4:38
  • Yes, I want to remove html tags. Can you display example code? Commented Aug 25, 2014 at 4:39
  • Also, why not just use php.net/strip_tags ? Commented Aug 25, 2014 at 4:42

2 Answers 2

4

Try this code for remove html tags in array values:

you can used single variable to remove tags means you can strig_tags() sample code for remove html :

<?php
echo strip_tags("Hello <b><i>world!</i></b>","<b>");
?>

and also remove html tags in array method:

function stripAllFields(&$fields) {
  foreach ($fields as $key => $value) {
         if (is_array($fields[$key])) { stripAllFields($fields[$key]); }
          else { $fields[$key] = strip_tags($value); }
     }
}

Here you can remove multi dimension array values also. And convert html code into bbcode in php :

Refer this url:

Refer Link 1

Refer Link 2

And also PHP function are present for BBcode create and parser:

PHP BBCODE_PARSER

PHP BBCODE_CREATE

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. My project is html convert to bbcode. Because I will remove html tags after I will replace bbcode tags as "<b>Hello</b> World!" to bbcode "[b]Hello[/b] World!". Can you introduce me?
@KemChat.. you asked about how to remove html code in array thats why i answer it..you can edit you question..i updated my answer please check it..
I can do it. Thank you
0

Works ok on my system. Issue from what I could tell is your font-family has single quotes making Angsana New a syntax error. Try this:

$string = '<span style="font-family: \'Angsana New\', serif;">Hello</span>';

1 Comment

corrected, thanks for the reminder. changed the " to \'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.