I try to get product variation meta data and my string contains thes html entity spaces
My code:
$_alusM2 = get_post_meta($product_id, '_alus_al', true);
It should give me _alus_al
field text and it looks like this: 8,6 m2 / 224 tk / 1350 kg
but I see many
before 8,6 m2
I've tried this:
$content = str_replace(' ',"",$_alusM2);
$content = preg_replace( '/\s+/', '', $content );
but still same issue.
If I var_dump($_alusM2);
then it says string(25)
so it is OK but why it gives so many white spaces
with echo?
My Answer:
You can try using the html_entity_decode function to convert the HTML entities like back to their corresponding characters. Here's an updated version of your code:
php
$_alusM2 = get_post_meta($product_id, '_alus_al', true);
$content = html_entity_decode($_alusM2);
$content = preg_replace('/\s+/', '', $content);
echo $content;
This should remove the entities before the string when you echo the content.
Rate this post
4 of 5 based on 4392 votesComments