Aphex22
Aphex22

Reputation: 93

How to use preg_replace and strip_tags together in PHP

Is it possible to use preg_replace and strip_tags together on the same string?

I'm trying to remove HTML tags and all non_alpha_numeric characters from a string using the following :

<?=strip_tags (preg_replace('/[^\da-z]/i', ' ', $line['features']))?>,

This is currently removing the non_alpha characters but leaving the tags minus the brackets/parenthesis.

Anybody help?

Upvotes: 1

Views: 280

Answers (1)

dops
dops

Reputation: 800

your preg_replace is removing the "<" ">" values so strip_tags doesn't recognise them as tags,

if you reverse the functions

<?=preg_replace('/[^\da-z]/i', ' ', strip_tags($line['features']));?>

it should work

Upvotes: 2

Related Questions