ok i'm trying to know what function where you can see if it contains something. like ex. does anyone know of a function like this?

if (func_contains('a') 
{
//action
}
else

Recommended Answers

All 7 Replies

I am not sure what your asking.. do you mean to create a function to see if $a contains something?

There is in_array But I'm not entirely sure if that's what you're looking for.

I am not sure what your asking.. do you mean to create a function to see if $a contains something?

like i'm trying to see if it like $_POST contains the character apostrophe or the letter A. i know bout the strip slashing but i'm trying to see if it does contain that character.

You can just use an if statement..

if($_POST['blah'] == 'a') {
do something 
} else if($_POST['blah'] == ''') {
do something else
}

if you are trying to see if a string "contains" a character, i would use a regex and the preg_match function

You can just use an if statement..

if($_POST['blah'] == 'a') {
do something 
} else if($_POST['blah'] == ''') {
do something else
}

i know i put that in the main... but what i mean the input may also contain something else. like ab. and i dont want to make a million if statements or cases.

$str = 'a';
$regex = "/" . $str . "/";
if (preg_match($regex,$_POST['blah'])) {
      do something if the str is found
}
else {
     do something if the str is not found
}

or use

$str = 'a';
if (strpos($_POST['blah'],$str) === false) {
    string not found
}
else {
    string found
}
Be a part of the DaniWeb community

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