String

Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

<?php
   $variable = "name";
   $literally = 'My $variable will not print!';

   print($literally);
   print "<br>";

   $literally = "My $variable will print!";
   print($literally);
?>

output

My $variable will not print!\n
My name will print

There are no artificial limits on string length - within the bounds of available memory, you ought to be able to make arbitrarily long strings.

Strings that are delimited by double quotes (as in "this") are preprocessed in both the following two ways by PHP −

  • Certain character sequences beginning with backslash (\) are replaced with special characters

  • Variable names (starting with $) are replaced with string representations of their values.

The escape-sequence replacements are −

Escape-sequence Replaced by
\r Newline
\r Carriage-return
\t Tab
$ Dollar sign itself
\" Double-quote
\ Single backslash

For detail: http://php.net/manual/en/regexp.reference.escape.php

Concatenation
<?php
   $string1="Hello World";
   $string2="1234";

   echo $string1 . " " . $string2;
?>
strlen

Returns the length of the given string.

<?php
   echo strlen("Hello world!");
?>
strpos

find the position of the string with same string.

<?php
   echo strpos("Hello world!","world");
?>
6

Date Formatting

date_format()

Returns the formatted date string on success or FALSEon failure.

date_format(new DateTime($rows[written_on]), 'm-d')

Trim

To remove white spaces in array
$trim_folders = array();
for($i=0; $i < sizeof($folders)-2;$i++){
    $trim_folders[] = str_replace(' ', '', $folders[$i]);
}

results matching ""

    No results matching ""