php 3 strings as options code example
Example 1: php string functions
substr()
===========
<?php
$output = substr('Hello', 1, 3);
$output1 = substr('Hello', -2);//starts from the back of the string
echo $output;
echo '<br>';
echo $output1;
?>
===============
strlen()
===============
$output = strlen('Hello');
echo $output;
?>
===============
strpos()
===============
$output = strpos('Hello World', 'o');
echo $output;
$output1 = strrpos('Hello World', 'o');
echo $output1;
================
trim()
================
$text = 'Hello World ';
var_dump($text);
echo '<br>';
$trimmed = trim($text);
echo $trimmed;
echo '<br>';
var_dump($trimmed);
==================
strtoupper()
==================
$text = 'Hello World';
$uppercase = strtoupper($text);
echo $uppercase;
==================
strtolower()
==================
$text = 'Hello World';
$lowercase = strtolower($text);
echo $lowercase;
==================
ucwords()
===================
$text = 'hello world';
$proppercase = ucwords($text);
echo $proppercase;
==================
str_replace()
==================
$text = 'hello world';
$wordreplace = str_replace('world', 'john', $text);
echo $wordreplace;
=================
is_string()
=================
$val = 'Hello';
$output = is_string($val);
echo $output;
echo '<br>';
$values = array(true, false, null, 'abc', 33, '33',
22.4, '22.4', '', ' ', 0, '0');
foreach($values as $value){
if(is_string($value)){
echo "{$value} is a string<br>";
}
}
=================
gzcompress()
=================
$string =
"a;laksd;lk;lkasd;lkas;lk;lkd;lkasd;lka;lskd;lka;lkd;lk
as;l;laksd;lk;lkasd;lkas;ldk;laskd;lakd;lkad;l
adslkjlkasjdlkjlkjaslkjaslkdjlkajdlkajdlkajd
alskdjlkasjdlkjadlkjadlkjadlkjadlajd
adlkjlkjalksjdlkjlkjlkjklajsda";
$compressed = gzcompress($string);
echo $compressed;
echo '<br>';
$original = gzuncompress($compressed);
echo $original;
Example 2: PHP strings
<?php
echo 'this is a simple string';
echo 'You can also have embedded newlines in
strings this way as it is
okay to do';
// Outputs: Arnold once said: "I'll be back"
echo 'Arnold once said: "I\'ll be back"';
// Outputs: You deleted C:\*.*?
echo 'You deleted C:\\*.*?';
// Outputs: You deleted C:\*.*?
echo 'You deleted C:\*.*?';
// Outputs: This will not expand: \n a newline
echo 'This will not expand: \n a newline';
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
?>