0

I have a php echo with regular expression as in

echo preg_replace("/(\[|\])/", '', $paramValue);

I also want to make sure that any spaces are replaced aka if we have hello / world it becomes hello/world

I am not good with regex

4 Answers 4

1

Try this.

For just space you can use:

$string = str_replace(' ', '', $string);

For whitespaces you can use:

$string = preg_replace('/\s+/', '', $string);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this for removing space using regular expression.

$string = "hello / world";
$string = preg_replace('/\s+/', '', $string);
echo $string;

result:

hello/world

Comments

0

Thanks this is what I did

            utag_data.ad_sec<?php echo ($i+1); ?> = "<?php 
                preg_replace("/(\[|\]) /", '', $paramValue);
                $paramValue = str_replace(' ', '', $paramValue); 
                echo $paramValue;
            ?>";

Comments

0

Regex

(\[|\]| )

PHP

echo preg_replace("/(\[|\]| )/", '', $paramValue);

Description

1st Capturing group (\[|\]| )
    1st Alternative: \[
        \[ matches the character [ literally
    2nd Alternative: \]
        \] matches the character ] literally
    3rd Alternative:  
        matches the character   literally

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.