Hi i want pattern for checking no white space.

Recommended Answers

Here you go, (?! +) that should work.

Jump to Post
^\s

For the example, it depends what you want? preg_match, preg_replace... ?

Jump to Post

All 7 Replies

Here you go, (?! +) that should work.

Hi joshl_1995 can you send me any example.

Member Avatar
^\s

For the example, it depends what you want? preg_match, preg_replace... ?

ok thakns

hi diafol i used this pattern in my this programme.

$string = "Ashok Kumar";

if(preg_match($pattern,$string)){
    echo "Pattern matched";
}else {
    echo "Pattern not matched";
}

but i dint get any result. it give same output for
$string ="AshokKumar" and
$string ="Ashok Kumar"

Here this works

<?php
    if (preg_match("/\s/", "hello there")) {
        echo "Match";
    } else {
        echo "No match";
    }
?>
Member Avatar

but i dint get any result. it give same output for

As I said, it depends on how you want to use it. If you want to just see if there's whitespace - see joshl

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.