|
|
CIX. Funkce pro pr�ci s �et�zci
V�echny tyto funkce r�zn�mi zp�soby pracuj� s �et�zci. N�kter�
specializovan�j�� funkce najdete v sekc�ch regul�rn�ch v�raz� a
obsluha URL.
Informace o chov�n� �et�zc�, zvl�t� v souvislosti s pou�it�m jednoduch�ch
uvozovek, dvojit�ch uvozovek a znak� opat�en�ch zp�tn�mi lom�tky, viz polo�ky
�et�zce v sekci
Typy tohoto
manu�lu.
Tyto funkce jsou k dispozici jako sou��st
standardn�ho modulu, kter� je v�dy dostupn�. K pou��v�n� t�chto funkc� nen� t�eba ��dn�
instalace, jsou sou��st� j�dra PHP.
Tyto konstanty jsou definov�ny t�mto roz���en�m a budou k dispozici pouze
tehdy, bylo-li roz���en� zkompilov�no spole�n� s PHP nebo dynamicky zavedeno
za b�hu.
- Obsah
- addcslashes -- Opat�it �et�zec lom�tky ve stylu jazyka C
- addslashes -- Opat�it �et�zec lom�tky
- bin2hex -- P�ev�st bin�rn� data na hexadecim�ln� reprezentaci
- chop -- Odstranit netisknuteln� znaky z konce �et�zce
- chr -- Vr�tit ur�it� znak
- chunk_split -- Rozd�lit �et�zec na men�� ��sti
- convert_cyr_string --
P�ev�st z jedn� znakov� sady Azbuky do jin�
- convert_uudecode --
Decode a uuencoded string
- convert_uuencode --
Uuencode a string
- count_chars -- Vr�tit informace o znac�ch pou�it�ch v �et�zci
- crc32 -- Spo��tat kontroln� sou�et crc32 �et�zce
- crypt -- Jednosm�rn� za�ifrov�n� �et�zce
- echo -- Vytisknout jeden nebo v�ce �et�zc�
- explode -- Rozd�luje �et�zec jin�m �et�zcem
- fprintf -- Write a formatted string to a stream
- get_html_translation_table --
Vrac� p�ekladovou tabulku pou��vanou v
htmlspecialchars() a
htmlentities()
- hebrev --
P�ev�st logick� Hebrejsk� text na vizu�ln� text
- hebrevc --
P�ev�st logick� Hebrejsk� text na vizu�ln� text s konverz� konc� ��dk�
- html_entity_decode --
Convert all HTML entities to their applicable characters
- htmlentities -- P�ev�st v�echny pou�iteln� znaky na HTML entity
- htmlspecialchars -- P�ev�st zvl�tn� znaky na HTML entity
- implode -- Spojit prvky pole pomoc� �et�zce
- join -- Spojit prvky pole pomoc� �et�zce
- levenshtein --
Spo��tat XXX Levenshteinovu vzd�lenost mezi dv�ma �et�zci
- localeconv -- Get numeric formatting information
- ltrim -- Odstranit netisknuteln� znaky ze za��tku �et�zce
- md5_file -- Calculates the md5 hash of a given filename
- md5 -- Spo��tat MD5 hash �et�zce
- metaphone -- Spo��tat metaphone kl�� �et�zce
- money_format -- Formats a number as a currency string
- nl_langinfo --
Query language and locale information
- nl2br -- P�ed v�echny konce ��dk� v �et�zci vlo�� HTML konce ��dk�
- number_format -- Format a number with grouped thousands
- ord -- Vr�tit ASCII hodnotu znaku
- parse_str -- Rozparsovat �et�zec do prom�nn�ch
- print -- Vytisknout �et�zec
- printf -- Vytisknout form�tovan� �et�zec
- quoted_printable_decode --
P�ev�st quoted-printable �et�zec na osmibitov� �et�zec
- quotemeta -- Opat�it lom�tky metaznaky
- rtrim -- Odstranit netisknuteln� znaky z konce �et�zce
- setlocale -- Set locale information
- sha1_file -- Calculate the sha1 hash of a file
- sha1 -- Calculate the sha1 hash of a string
- similar_text -- Spo��tat podobnost dvou �et�zc�
- soundex -- Spo��tat soundex kl�� �et�zce
- sprintf -- Vr�tit form�tovan� �et�zec
- sscanf -- Rozparsovat vstupn� �et�zec podle form�tu
- str_ireplace --
Case-insensitive version of str_replace().
- str_pad -- Doplnit �et�zec jin�m �et�zcem na ur�itou d�lku
- str_repeat -- Opakovat �et�zec
- str_replace --
Nahradit v�echny v�skyty jednoho �et�zce dal��m �et�zcem
- str_rot13 -- Perform the rot13 transform on a string
- str_shuffle -- Randomly shuffles a string
- str_split --
Convert a string to an array
- str_word_count --
Return information about words used in a string
- strcasecmp --
Bin�rn� bezpe�n� case-insensitive porovn�n� �et�zc�
- strchr -- Naj�t prvn� v�skyt znaku
- strcmp -- Bin�rn� bezpe�n� porovnat �et�zce
- strcoll -- Locale based string comparison
- strcspn --
Naj�t d�lku �vodn�ho segmentu neodpov�daj�c�ho masce
- strip_tags -- Odstranit z �et�zce HTML a PHP tagy
- stripcslashes --
Un-quote string quoted with addcslashes()
- stripos --
Find position of first occurrence of a case-insensitive string
- stripslashes --
Zru�it escapov�n� proveden� funkc� addslashes()
- stristr --
strstr() bez rozli�en� velikosti p�smen
- strlen -- Zjistit d�lku �et�zce
- strnatcasecmp --
Case-insensitive textov� porovn�n� s vyu�it�m "natural order" algoritmu
- strnatcmp -- Porovn�n� �et�zc� algoritmem "p�irozen�ho t��d�n�"
- strncasecmp --
Bin�rn� bezpe�n� case-insensitive porovn�n� prvn�ch n znak� �et�zc�
- strncmp --
Bin�rn� bezpe�n� porovn�n� prvn�ch n znak� v �et�zc�ch
- strpbrk --
Search a string for any of a set of characters
- strpos -- Naj�t pozici prvn�ho v�skytu �et�zce
- strrchr -- Naj�t posledn� v�skyt znaku v �et�zci
- strrev -- Obr�tit �et�zec
- strripos --
Find position of last occurrence of a case-insensitive string in a string
- strrpos -- Naj�t pozici posledn�ho v�skytu znaku v �et�zci
- strspn -- Zjistit d�lku �vodn�ho segmentu odpov�daj�c�ho masce
- strstr -- Naj�t prvn� v�skyt �et�zce
- strtok -- Tokenize string
- strtolower -- Zm�nit �et�zec na mal� p�smena
- strtoupper -- Zm�nit �et�zec na velk� p�smena
- strtr -- P�elo�it ur�it� znaky
- substr_compare --
Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characters
- substr_count -- Spo��tat po�et v�skyt� �et�zce
- substr_replace -- Nahradit ��st �et�zce jin�m �et�zcem
- substr -- Vr�tit ��st �et�zce
- trim --
Odstranit netisknuteln� znaky ze za��tku a konce �et�zce
- ucfirst -- Zm�n� prvn� p�smeno �et�zce na velk�
- ucwords --
Zm�nit prvn� znak ka�d�ho slova v �et�zci na velk� p�smeno
- vprintf -- Output a formatted string
- vsprintf -- Return a formatted string
- wordwrap --
Zal�mat �et�zec na dan� po�et znak� pomoc� break znaku
add a note
User Contributed Notes
Funkce pro pr�ci s �et�zci
andy a t onesandzeros d o t biz
09-Nov-2004 10:54
I use these little doo-dads quite a bit. I just thought I'd share them and maybe save someone a little time. No biggy. :)
// returns true if $str begins with $sub
function beginsWith( $str, $sub ) {
return ( substr( $str, 0, strlen( $sub ) ) == $sub );
}
// return tru if $str ends with $sub
function endsWith( $str, $sub ) {
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) == $sub );
}
// trims off x chars from the front of a string
// or the matching string in $off is trimmed off
function trimOffFront( $off, $str ) {
if( is_numeric( $off ) )
return substr( $str, $off );
else
return substr( $str, strlen( $off ) );
}
// trims off x chars from the end of a string
// or the matching string in $off is trimmed off
function trimOffEnd( $off, $str ) {
if( is_numeric( $off ) )
return substr( $str, 0, strlen( $str ) - $off );
else
return substr( $str, 0, strlen( $str ) - strlen( $off ) );
}
[tab!]
27-Oct-2004 07:29
//
// string strtrmvistl(string str, [int maxlen = 64])
//
// like strtrmvistl(). returns only the start and end chunk
// in an array for further processing.
//
function strtrmvistl_a($str, $maxlen = 64) {
$res = array('start' => $str, 'end' => 0);
if(($len = strlen($str = chop($str))) > ($maxlen = max($maxlen, 12))) {
$res['start'] = substr($str, 0, $maxlen - 3);
if($len > ($maxlen - 3)) {
$endlen = min(($len - strlen($res['start'])), $maxlen - 3);
$res['start'] .= "...";
$res['end'] = "..." . substr($str, $len - $endlen);
}
}
return($res);
}
[tab!]
27-Oct-2004 07:29
//
// string strtrmvistl( string str, [int maxlen = 64],
// [bool right_justify = false],
// [string delimter = "<br>\n"])
//
// splits a long string into two chunks (a start and an end chunk)
// of a given maximum length and seperates them by a given delimeter.
// a second chunk can be right-justified within maxlen.
// may be used to 'spread' a string over two lines.
//
function strtrmvistl($str, $maxlen = 64, $right_justify = false, $delimter = "<br>\n") {
if(($len = strlen($str = chop($str))) > ($maxlen = max($maxlen, 12))) {
$newstr = substr($str, 0, $maxlen - 3);
if($len > ($maxlen - 3)) {
$endlen = min(($len - strlen($newstr)), $maxlen - 3);
$newstr .= "..." . $delimter;
if($right_justify)
$newstr .= str_pad('', $maxlen - $endlen - 3, ' ');
$newstr .= "..." . substr($str, $len - $endlen);
}
return($newstr);
}
return($str);
}
[tab!]
27-Oct-2004 07:27
//
// string strtrmvis(string str, [int maxlen = 64])
//
// truncate a long string to a given maximum length by inserting
// a placeholder in the middle
//
function strtrmvis($str, $maxlen = 64) {
if(strlen($str = chop($str)) > ($maxlen = max($maxlen, 12))) {
$chunklen = ($maxlen / 2);
$str = substr($str, 0, $chunklen - 2) . ".. .." .
substr($str, $chunklen - (2 * $chunklen) + 3, $chunklen);
}
return($str);
}
[tab!]
27-Oct-2004 07:26
//
// string strtrevis(string str, [int maxlen = 64])
//
// truncate a long string to a given maximum length by appending
// a placeholder at the end
//
function strtrevis($str, $maxlen = 64) {
if(strlen($str = chop($str)) > ($maxlen = max($maxlen, 6)))
$str = substr($str, 0, $maxlen - 3) . "...";
return($str);
}
terry dot greenlaw at logicalshift dot com
12-Aug-2004 05:52
Here's a simpler "simplest" way to toggle through a set of 1..n colors for web backgrounds:
<?php
$colours = array('#000000', '#808080', '#A0A0A0', '#FFFFFF');
$color = next($colors) or $color = reset($colors);
?>
The code doesn't need to know anything about the number of elements being cycled through. That way you won't have to tracking down all the code when changing the number of colors or the color values.
| |