Попробуйте это:
/**
* Function to strip away a given string
**/
function remove_nbsp($string){
$string_to_remove = " ";
return str_replace($string_to_remove, "", $string);
}
# Example data array
$steps = array("<p>step1</p>", "<p>step2</p>", "<p>step3</p>", "<p> </p>", " ", "<p> </p>", "<p>step4</p>");
$steps = array_map("strip_tags", $steps);
//Strip_tags() will remove the HTML tags
$steps = array_map("remove_nbsp", $steps);
//Our custom function will remove the character
$steps = array_filter($steps);
//Array_filter() will remove any blank array values
var_dump($steps);
/**
* Output:
array(4) {
[0]=>
string(5) "step1"
[1]=>
string(5) "step2"
[2]=>
string(5) "step3"
[6]=>
string(5) "step4"
}
*/
Возможно, вам даже будет проще сделать foreach ():
foreach($steps as $dirty_step){
if(!$clean_step = trim(str_replace(" ", "", strip_tags($dirty_step)))){
//Ignore empty steps
continue;
}
$clean_steps[] = $clean_step;
}