- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_cyr_string
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- echo
- explode
- fprintf
- get_html_translation_table
- hebrev
- hebrevc
- hex2bin
- html_entity_decode
- htmlentities
- htmlspecialchars_decode
- htmlspecialchars
- implode
- join
- lcfirst
- levenshtein
- localeconv
- ltrim
- md5_file
- md5
- metaphone
- money_format
- nl_langinfo
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_decode
- quoted_printable_encode
- quotemeta
- rtrim
- setlocale
- sha1_file
- sha1
- similar_text
- soundex
- sprintf
- sscanf
- str_getcsv
- str_ireplace
- str_pad
- str_repeat
- str_replace
- str_rot13
- str_shuffle
- str_split
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- stripslashes
- stristr
- strlen
- strnatcasecmp
- strnatcmp
- strncasecmp
- strncmp
- strpbrk
- strpos
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtok
- strtolower
- strtoupper
- strtr
- substr_compare
- substr_count
- substr_replace
- substr
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- vsprintf
- wordwrap
Коментарии
Alternative Way:
To get all the text before the first occurence.
-----------------------------------------------
INCLUDING A NEEDLE:
$string1 = "I need cookies & soda.";
$needle = "cookies";
//find length of the needle
$needle_len = strlen($needle);
//find postion
$position_num = strpos($string1,$needle) + $needle_len;
//cut the string
$result_string = substr("$string1",0,$position_num);
//display it
echo"$result_string"; // I need cookies
-----------------------------------------------
SHORTER VERSION:
$result_string = substr("$string1",0,strpos($string1,$needle)+strlen($needle));
echo"$result_string";//I need cookies
-----------------------------------------------
EXCLUDING THE NEEDLE:
$result_string = substr("$string1",0,strpos($string1,$needle));
echo"$result_string";// I need
-----------------------------------------------
FREE EMAIL JUNK?
This is probably useful for processing emails.
For example, someone sends email to your server from Yahoo account.
Free email always comes with wasted stuff like...
"Do you Yahoo!? The New Yahoo! Shopping - with improved product search ".
We can delete the phrase like this:
$needle="Do you Yahoo!?";
$result_string = substr("$emailstring",0,strpos($emailstring, $needle));