Follow us on Facebook
Faucibus toroot menuts
PHP String function
String in PHP is a set of character sets which we can manipulate and show in our own way.
There are few inbuilt PHP functions for String only.
Here is the list
● STR_LEN
This function finds string length in character.
Example :
<br>
< strong>Type Your text : < /strong>
<formname>="form1"method="post"action=" ">
< p>
< textarea name="comment"id="textarea"cols="45"rows="5"< /textarea>
< /p>
< p>
< inputtype="submit"name="button"id="button"value="Post Now">
< /p>
< /form>
After submitting the form you will see this.
● SUBSTR
Substr function is helpful in truncating any string. This function requires three parameters. First, string, starting point and third up to how many characters.
Example :
<br>
< strong>Type Your text : < /strong>
<formname>="form1"method="post"action=" ">
< p>
< textarea name="comment"id="textarea"cols="45"rows="5">
Share all your special moments on Skype, whenever you want, wherever you are – all from your tablet.
Share all your special moments on Skype, whenever you want, wherever you are – all from your tablet.
Share all your special moments on Skype, whenever you want, wherever you are – all from your tablet.
Share all your special moments on Skype, whenever you want, wherever you are – all from your tablet.
< /textarea>
< /p>
< p>
< inputtype="submit"name="button"id="button"value="Post Now">
</p>
< /form>
● STR_REPLACE
Example :
<br>
< strong>Type Your text : < /strong>
<formname>="form1"method="post"action=" ">
< p>
< textarea name="comment"id="textarea"cols="45"rows="5">< ?php echo'THis is shit and and dont be huffy. Its awsome words'?>
< /textarea>
< /p>
< p>
< inputtype="submit"name="button"id="button"value=>"Post Now"
< /p>
< /form>
● UCFIRST
This function makes the first character of any string to Upper case.
Example :
● Strtoupper
This function converts whole string into upper case.
Example :
● Strtolower
As contrary to strtoupper, this function converts whole string into lower case.
Example :
Explode
Explode function is PHP is a very useful where one can convert the string having fixed separator into an array and then can display that in one’s own format.
Explode function takes two parameters. First the separator and in second it takes string.
Example:
Now we will show the array value into dropdown.
Let’s take an example:
Suppose you are developing an e-commerce website and admin types color names of the product in comma separated value. You can store the value in a single field as comma separated and later you can use that as dropdown value after exploding.
Implode
Opposite to explode there is imploding function. In implode function; you can change separator characters into your own.
Example:
Result: