php strpos
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
php strpos
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
php obscure string
/**
* @param string|string[] $plain
* @param int $revealStart
* @param int $revealEnd
* @param string $obscuration
* @return string|string[]
*/
function obscure(
$plain,
int $revealStart = 1,
int $revealEnd = 0,
string $obscuration = '*'
) {
if (is_array($plain)) {
return array_map(
function ($plainPart) use ($revealStart, $revealEnd, $obscuration) {
return obscure($plainPart, $revealStart, $revealEnd, $obscuration);
},
$plain
);
}
$plain = (string) $plain;
return mb_substr($plain, 0, $revealStart)
. str_repeat(
$obscuration,
max(
0,
mb_strlen($plain) -
($revealStart + $revealEnd)
)
)
. mb_substr(
$plain,
-$revealEnd,
$revealEnd
);
}
php heredoc
$output = <<<HTML
<p>Lorem ipsum dolor sit amet consectetur<p>
<a href="{$foobar}">click here</a>
HTML;
php string functions
#String Functions
substr() #Returns a portion of a string
===========
<?php
#substr() Returns a portion of a string
$output = substr('Hello', 1, 3);
$output1 = substr('Hello', -2);//starts from the back of the string
echo $output;
echo '<br>';
echo $output1;
?>
===============
strlen() #Returns the length of a string
===============
$output = strlen('Hello');
echo $output;
?>
===============
strpos() #finds the position of the first occurence of a sub string
===============
$output = strpos('Hello World', 'o');
echo $output;
$output1 = strrpos('Hello World', 'o'); #last occurance
echo $output1;
================
trim() # trims white space
================
$text = 'Hello World ';
var_dump($text);
echo '<br>';
$trimmed = trim($text);
echo $trimmed;
echo '<br>';
var_dump($trimmed);
==================
strtoupper() # makes everything uppercase
==================
$text = 'Hello World';
$uppercase = strtoupper($text);
echo $uppercase;
==================
strtolower() #makes everything lowercase
==================
$text = 'Hello World';
$lowercase = strtolower($text);
echo $lowercase;
==================
ucwords() #Capitalizes every word
===================
$text = 'hello world';
$proppercase = ucwords($text);
echo $proppercase;
==================
str_replace() #Replace all occurances of a search string
#with a replacement
==================
$text = 'hello world';
$wordreplace = str_replace('world', 'john', $text);
echo $wordreplace;
=================
is_string() #Checks to see if it is a 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() # Compress a string
=================
$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;
heredoc php
<?php
$str = <<<EOD
Exemple de chaîne
sur plusieurs lignes
en utilisant la syntaxe Heredoc.
EOD;
/* Exemple plus complexe, avec des variables. */
class foo
{
var $foo;
var $bar;
function __construct()
{
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}
$foo = new foo();
$name = 'MyName';
echo <<<EOT
Mon nom est "$name". J'affiche quelques $foo->foo.
Maintenant, j'affiche quelques {$foo->bar[1]}.
Et ceci devrait afficher un 'A' majuscule : \x41
EOT;
?>
php string
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us