Sorry if I am a PHP noob...
I am trying to remove the whitespace from a user's input so that the "tel link" doesn't have any spaces within it.
My code looks like this:
<div class="nt-menu-phone-number">
<?php
if( !empty ($nt_theme_options['menu_style1_number'])) { ?>
<a href="tel:<?php echo esc_html($nt_theme_options['menu_style1_number']); ?>"><?php echo esc_html($nt_theme_options['menu_style1_number']); ?></a>
<?php } ?>
</div>
How do I go about removing the whitespace? I have tried putting the trim() function around it but no luck.
Any helps greatly appreciated, thanks.
You can follow u the code that i have given below.
To remove all white spaces in the sting, use preg_replace();
Output: 0812345678
<?php
$nt_theme_options['menu_style1_number'] = '08 1234 5678';
?>
<div class="nt-menu-phone-number">
<?php
if( !empty ($nt_theme_options['menu_style1_number'])) { ?>
<a href="tel:<?php echo preg_replace('/\s+/', '',$nt_theme_options['menu_style1_number']); ?>"><?php echo preg_replace('/\s+/', '',$nt_theme_options['menu_style1_number']); ?></a>
<?php } ?>
</div>