Hi, I am getting a PHP string which I need to strip the spaces out of. I have used the following code but when I echo $classname
it just displays the string sti
The problem might be the character not being a space, but another whitespace character.
Try
$classname = preg_replace('/\s/', '', $fieldname);
use trim like this
TRIM($fieldname);
EDIT:
preg_replace('/\s+/', '', $fieldname);
Try to add u-parameter for regex-pattern, because a string can have UTF-8 encoding:
$classname = preg_replace('/\s+/u', '', $fieldname);
It could be that the space is not really a space, but other form of whitesspace.
You might want to try:
$classname = preg_replace('/\s+/', '', $fieldname);
From here.
If you know the white space is only due to spaces, you can use:
$classname = str_replace(' ','',$fieldname );
But if it could be due to space, you can use:
$classname = preg_replace('/\s+/','',$fieldname )
<?php
$fieldname = "I am 21 Years Old";
$classname = str_replace(' ', '', $fieldname);
echo $classname;
?>
This runs perfectly.
Check value return by this function: the_sub_field('venue_title')
;