PHP 部分函數

PHP ucwords() 

實例

把每一個單詞的首字符轉換爲大寫:php

<?php
echo ucwords("hello world");
?>

定義和用法

ucwords() 函數把字符串中每一個單詞的首字符轉換爲大寫。數據庫

註釋:該函數是二進制安全的。安全

相關函數:

  • lcfirst() - 把字符串中的首字符轉換爲小寫函數

  • strtolower() - 把字符串轉換爲小寫加密

  • strtoupper() - 把字符串轉換爲大寫spa

  • ucfirst() - 把字符串中的首字符轉換爲大寫.net

語法

ucwords(string)



PHP ucfirst()

實例

把 "hello" 的首字符轉換爲大寫:code

<?php
echo ucfirst("hello world!");
?>

定義和用法

ucfirst() 函數把字符串中的首字符轉換爲大寫。orm

相關函數:

  • lcfirst() - 把字符串中的首字符轉換爲小寫xml

  • strtolower() - 把字符串轉換爲小寫

  • strtoupper() - 把字符串轉換爲大寫

  • ucwords() - 把字符串中每一個單詞的首字符轉換爲大寫

語法

ucfirst(string)



PHP simplexml_load_string()

定義和用法

simplexml_load_string() 函數把 XML 字符串載入對象中。

若是失敗,則返回 false。

語法

simplexml_load_file(string,class,options,ns,is_prefix)


返回值

返回類 SimpleXMLElement 的一個對象,該對象的屬性包含 XML 文檔中的數據。若是失敗,則返回 false。


例子

<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
XML;

$xml = simplexml_load_string($xmlstring);

var_dump($xml);
?>

輸出:

object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget the meeting!"
}



mcrypt_generic

(PHP 4 >= 4.0.2, PHP 5)

mcrypt_generic — 加密數據

說明

string mcrypt_generic ( resource $td , string $data )

本函數用來加密數據。 傳入數據長度必須是 n * 分組大小,不然須要後補 "\0"。 本函數返回加密後的數據。 注意,根據數據補齊不一樣, 返回的數據可能比輸入的數據長度有所增長。

若是你須要把加密後的數據保存到數據庫, 請確保保存 mcrypt_generic 返回的完整的字符串, 不然將沒法正確解密。 若是原始數據有 10 個字符,分組大小爲 8 (使用 mcrypt_enc_get_block_size() 獲取分組大小), 則數據庫中至少須要 16 個字符來保存數據。 請注意mdecrypt_generic() 函數返回的數據也會是 16 個字符。 使用 rtrim($str, "\0") 移除字符串末尾的 0 。

若是你在例如 MySQL 這樣的數據庫中存儲數據, 請注意 varchar 類型的字段會在插入數據時自動移除字符串末尾的「空格」。 因爲加密後的數據多是以空格(ASCII 32)結尾, 這種特性會致使數據損壞。 請使用 tinyblob/tinytext(或 larger)字段來存儲加密數據。

參數

返回值

返回加密後的數據。

相關文章
相關標籤/搜索