startsWith and endsWith methods in Laravel

The startsWith and endsWith methods check whether a string starts or ends with one or more substrings: Str::startsWith(’.htaccess’, ‘.hta’); // Returns true Str::endsWith(’index.html’, array(’html’, ‘php’)); // Returns true
Continue reading…

Enjoyed this post? Share it!

 
 

Common template tags in wordpress

the_permalink() — Displays the URL of your post. the_title() — Displays the title of the post. the_ID() — Displays the unique ID of your post. the_content() — Displays the full content of your post. the_excerpt() — Displays the excerpt of your post. If the Excerpt field is filled out on the Post edit screen, that […]
Continue reading…

Enjoyed this post? Share it!

 
 

Selecting a MongoDB database in PHP

After connecting to the database server, you can obtain a handle to the database using the following syntax. $db = $connection->selectDB(’databasename’); A shorthand way to selecting a database is as follows: $db = $connection->databasename; If there is no database with the specified name, MongoDB will automatically create it.
Continue reading…

Enjoyed this post? Share it!

 
 

Connecting to a MongoDB Database Server in PHP

After installing the MongoDB database, use the following code to connect to the MongoDB database. $connection = new Mongo(); The above code connects to the database using default credentials.i.e host is localhost and port is 27017. To explicitly connect to a remote host where MongoDB is housed, use the following syntax. $connection = new Mongo( […]
Continue reading…

Enjoyed this post? Share it!

 
 

Connect to MySql and select database using PHP

The following code is an example of how to connect to a mysql server and select a database to query. We should always free up resources you don’t need anymore i.e make sure that mysql_close() executes at the end. This makes your code more efficient and reduces the possibility of errors. <?php $DB_HOST = "localhost"; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Google Maps API to calculate location distance in PHP

This example shows how to use the Google maps API to calculate distance between two places in PHP $result = file_get_contents(’http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Raleigh,NC&sensor=false’); $result = json_decode($results); $distance = $result->routes->legs->distance[’text’]; echo $distance // Outputs: "xxx mi"
Continue reading…

Enjoyed this post? Share it!

 
 

Type Validation Functions in PHP

is_array() – Test for Arrays is_bool() – Test for Booleans (TRUE, FALSE) is_float() – Test for Floating-point numbers is_int() – Test for Integers is_null() – Test for NULLs is_numeric() – Test forNumeric values, even as a string (e.g., ‘ 20’ ) is_resource() – Test for Resources, like a database connection is_scalar() – Test for Scalar […]
Continue reading…

Enjoyed this post? Share it!

 
 

Compare two arrays to see if value from form post exists in PHP

<?php $choices = array(’my choice 1′, ‘my choice 2’, ‘my choice 3’);   $valid = true; if (is_array($_GET[’inputArray’])) { $valid = true; foreach($_GET[’inputArray’] as $input) { if (!in_array($input, $choices)) { $valid = false; } }   if ($valid) { echo "Input Value were found in choices"; } } ?>
Continue reading…

Enjoyed this post? Share it!

 
 

Using Radio buttons in PHP Form

<html> <body>   <form action="mychoice.php" method="post"> <b>Enter Name:</b> <input type="text" size="45" name="username"> <br> <b>Please select your favorite animal:</b> <br> <input type="radio" name="animal" value="dog">Dog <input type="radio" name="animal" value="cat">Cat <input type="radio" name="animal" value="fish">Fish <br> <input type="submit" value="Submit"> </form>   </body> </html> File: mychoice.php <html> <head> <title>Form submission</title> </head> <body> <br>   <?php $username = $_POST[’username’]; $animal = […]
Continue reading…

Enjoyed this post? Share it!