String functions in PHP – WEBSITE DEVELOPMENT

In this video

Today we are going to learn string functions in PHP. In our last lecture we learned about datatypes in PHP. If you haven’t watched it yet then here is the link of tutorial http://tutorialhive.net/2018/09/08/4-php-datatypes-php-website-development/. Today’s tutorial is about string functions in PHP.

String functions in PHP

In this tutorial we will learn about string functions in PHP and how to manipulate strings. First step is to run wamp server. Run wamp and after that go into drive where you installed wamp server. Open folder Wamp after that open folder www. Now create a new folder in ‘www‘you can give any name to your folder, I am naming it tutorialhive. In folder create a file with name index.php. In your editor open your php file.

Built in PHP functions for string manipulation

Following are the built in functions in php which are used to manipulate strings

Find string length

Strlen(string);

This function find and display the length of given string including space between string, so here is code:

<?php

$myString=”Hello world”;

echo strlen($myString);

?>

Echo is used before function to display result.

Output: 11

Find alphabet count

Strlen(string);

This function find and display the length of given string including space between string, so here is code:

<?php

$myString=”Hello world”;

echo strlen($myString);

?>

Echo is used before function to display result.

Output: 11

Find word count for sentences

str_word_count (string);

This function find and display the no of words in a sentence, so here is code:

<?php

$myString=”Hello world Hello world”;

echo str_word_count ($myString);

?>

Output: 4

Reverse word

This function reverse words, so here is code:

<?php

$myString=”Hello”;

echo strrev($myString);

?>

Output: olleH

Replace function

str_replace(search , replace , subject);

This function is used to search a specific word and replace it with another word. It has three parameters. Search parameter contain word you want to search in code then there is replace which contain word you want to write. Subject contain string, so here is code:

<?php

$myString=”Hello world”;

echo str_replace(“world” , “pakistan” , $myString );

?>

Output:Hello Pakistan

String functions in PHP tutorial end here. In next tutorial we will learn about constants in php. If you have any queries you can ask us on our Facebook page link is given below, Thank you for watching us.

ABOUT US

Tutorial Hive’s mission is to provide quality education to all our community. Tutorial Hive’s mission is to provide free education to all those who cannot afford BIG FEE of institutes. We aim specifically to empower youth to understand programming related knowledge which further helps the society to reduce complex problems through applications. Why Tutorial Hive? We not only provide the theoretical knowledge but also provide the actual implementation with working sample applications. Tutorial Hive cannot achieve its mission without the help of our community. So, please if you think you can help in any manner feel free to contact us. Or if you see any mistake in our content which can be modified/corrected then please leave us a message

We are always open for suggestions.

Facebook: www.facebook.com/hbss2015

Subscribe on YouTube: https://www.youtube.com/channel/UCOUy6kTpedj7s6HOqM0c08w

Follow us on Social Media

You might be interested in

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *