How to handle JSON request with PHP

There are some good tutorials which might help you send a JSON request via PHP cURL:
Getting jSON Data with PHP (curl method)

Here is a simple script that shows how to handle the JSON requests with PHP:

$stream = fopen('php://input', 'r');
$json = stream_get_contents($stream);
fclose($stream);       
$json = json_decode($json, true);

Simple PHP object to check for valid email

Here is a simple code for PHP that will help you check if a given string is a valid e-mail!

function checkEmail($email){
    $regularExpression="/^[a-z]+[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]+\.[a-zA-Z]{2,4}$/";
    if(preg_match($regularExpression, $email))
    {
        return "Valid";
    }

   return  "Not Valid";
}
$isValid = checkEmail("someone@email.com");

PHP code to check if a string is a part of another string

That is a fairly simple peace of code that I always get to search for when I need it. That is why I decided to put it into my blog so that I could have an eased access to it when I need it.

This simple code helps me find whether a given string is a part of a larger string.

if(strpos($text_to_search, $text_to_find)===true)
{
     //some code
}
else
{
    //another code
}

The key here is the triple equal sign…

Read More

Categories