本文整理汇总了PHP中cleanString函数的典型用法代码示例。如果您正苦于以下问题:PHP cleanString函数的具体用法?PHP cleanString怎么用?PHP cleanString使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cleanString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: emptyString
/**
* Check string and return "none" if empty
*
* @param type $string
*/
function emptyString($string)
{
if (strlen(cleanString($string)) == 0) {
return '<span class="empty">none</span>';
}
return $string;
}
示例2: getGlobals_help
function getGlobals_help($getPage_connection2)
{
// session: admin
if (isset($_SESSION["admin"])) {
$_SESSION["admin"] = cleanString($_SESSION["admin"], true);
} else {
$_SESSION["admin"] = 0;
}
// else
// session: nation_id
if (isset($_SESSION["nation_id"])) {
$_SESSION["nation_id"] = cleanString($_SESSION["nation_id"], true);
} else {
$_SESSION["nation_id"] = 0;
}
// else
// session: user_id
if (isset($_SESSION["user_id"])) {
$_SESSION["user_id"] = cleanString($_SESSION["user_id"], true);
} else {
$_SESSION["user_id"] = 0;
}
// else
// get info
//$_SESSION["userInfo"] = getUserInfo($getPage_connection2,$_SESSION["user_id"]);
//$_SESSION["nationInfo"] = getNationInfo($getPage_connection2,$_SESSION["nation_id"]);
}
示例3: getGoogleImg
/**
* Make a search from the Google Image API,
* Browse the results,
* Exclude "not found", "forbidden", "unavailable" status,
* Return the path of the found image.
* If not found, return an empty string.
* If $thumb = true return the thumbnail image width, ortherwise return the full image width.
* @param string $search
* @param bool $thumb
*/
function getGoogleImg($search, $thumb = false)
{
// Clean search string to remove special chars, and replace spaces with +
$clean_str = cleanString($search, array(), '+');
// If $thumb = true, look for the thumbnail url, otherwise look for the full image url
$target = $thumb ? 'tbUrl' : 'url';
// Construct the Google Image API query
$query = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=' . urlencode($clean_str);
// Get the result from query, returns a JSON object
$json = file_get_contents($query);
// Converts the JSON object in PHP array
$results = json_decode($json, true);
// If there are results from the query
if (!empty($results["responseData"]["results"])) {
// Browse each result from response and set it in $result
foreach ($results["responseData"]["results"] as $result) {
// Retrieve the HTTP headers
$file_headers = @get_headers($result[$target]);
// If HTTP headers don't contain status 403 (forbidden), 404 (not found) or 503 (unavailable)
if (strpos($file_headers[0], '403') === false && strpos($file_headers[0], '404') === false && strpos($file_headers[0], '503') === false) {
// Return the absolute image path (http://...) from result with $target as key
return $result[$target];
}
}
}
// No image found, return an empty string
return '';
}
示例4: findValue
function findValue($delimeter, $attrib, $xml)
{
$val = "";
$xml = split("\n", $xml);
foreach ($xml as $line) {
if (strpos($line, $delimeter) !== FALSE) {
$val = $line;
break;
}
}
if ($val) {
$val = split('"', $val);
$tmp = split(' ', $val[0]);
$val[0] = trim(str_replace("<" . $delimeter, "", $val[0]));
$flag = 0;
foreach ($val as $x) {
if ($flag) {
return $x;
}
if (cleanString($x) == $attrib) {
$flag = 1;
}
}
}
return FALSE;
}
示例5: cleanOutputForEmployee
function cleanOutputForEmployee($employee)
{
$a = cleanString(8, $employee['Units']);
$b = cleanString(45, $employee['Full Name']);
$c = " {$employee['Employee Number']}";
return "{$a}|{$b}|{$c}";
}
示例6: checkStandard
/**
* checkStandard
* \brief check the passed in list against the passed in standard.
*
* The two lists are expected to be arrays with the following format:
*
* List to be check: associative array with keys: count, showLink,
* testOrLink.
*
* Standard list: associative array, where the key is the count and the
* value is the text to compare.
*
* @param associative array $list
* @param associative array $standard
*
* @return empty array on success, array of errors on fail.
*
*/
function checkStandard($list, $standard, $testName)
{
if (empty($list)) {
return array('ERROR! empty list passed in');
}
if (empty($standard)) {
return array('ERROR! empty Standard list passed in');
}
if (strlen($testName) == 0) {
return array('ERROR! no testName supplied');
}
$results = array();
foreach ($list as $uiData) {
$cleanText = cleanString($uiData['textOrLink']);
print "ckSTDB: cleanText is:{$cleanText}\n";
if (array_key_exists($cleanText, $standard)) {
$stdCount = $standard[$cleanText];
if ($stdCount != $uiData['count']) {
$results[] = "{$testName} FAILED! Should be {$stdCount} files " . "got:{$uiData['count']} for row with text:\n{$cleanText}\n";
}
} else {
$results[] = "{$testName} FAILED! {$cleanText} did not meet the test Standard\n";
}
}
//print "ckStdDB: results are:\n";print_r($results) . "\n";
return $results;
}
示例7: __construct
public function __construct($first_name, $last_name, $username, $password, $db)
{
$this->first_name = cleanString($first_name);
$this->last_name = cleanString($last_name);
$this->username = cleanString($username);
$this->password = cleanString($password);
$this->db = $db;
$this->insertUser();
}
示例8: removeLastWord
function removeLastWord($value)
{
$value = cleanString($value);
if (ctype_upper(substr($value, strlen($value) - 1, strlen($value)))) {
$value = substr($value, 0, strlen($value) - 1);
$value = cleanString($value);
}
return $value;
}
示例9: getGlobals_search
function getGlobals_search($getPage_connection2)
{
// session: admin
if (isset($_SESSION["admin"])) {
$_SESSION["admin"] = cleanString($_SESSION["admin"], true);
} else {
$_SESSION["admin"] = 0;
}
// else
// session: results output
if (isset($_SESSION["results_output"])) {
} else {
$_SESSION["results_output"] = "Search length requirements are not met! Search must be 5-75 characters long.";
}
// else
if (count($_POST)) {
// post: search terms
if (isset($_POST["search"])) {
$_SESSION["search"] = cleanString($_POST["search"], false);
} else {
$_SESSION["search"] = "";
}
// else
$_SESSION["results"] = array("");
// parse results into separate strings
if (stristr($_SESSION["search"], " ") === false) {
$_SESSION["results"][0] = $_SESSION["search"];
} else {
$_SESSION["results"] = explode(" ", $_SESSION["search"]);
}
// else
} else {
if (count($_GET)) {
}
}
// else if
// session: nation_id
if (isset($_SESSION["nation_id"])) {
$_SESSION["nation_id"] = cleanString($_SESSION["nation_id"], true);
} else {
$_SESSION["nation_id"] = 0;
}
// else
// session: user_id
if (isset($_SESSION["user_id"])) {
$_SESSION["user_id"] = cleanString($_SESSION["user_id"], true);
} else {
$_SESSION["user_id"] = 0;
}
// else
// get info
//$_SESSION["userInfo"] = getUserInfo($getPage_connection2,$_SESSION["user_id"]);
//$_SESSION["nationInfo"] = getNationInfo($getPage_connection2,$_SESSION["nation_id"]);
}
示例10: __construct
public function __construct($password, $username, $db)
{
//echo "password: ".$password. "<br>";
//echo "username: ".$username. "<br>";
$this->username = cleanString($username);
$password = cleanString($password);
$this->password = hashPasswords($password, $this->username);
//echo $this->password. "<br>";
$this->db = $db;
$this->sqlSelect();
}
示例11: getGlobals_deactivate
function getGlobals_deactivate($getPage_connection2)
{
// session: admin
if (isset($_SESSION["admin"])) {
$_SESSION["admin"] = cleanString($_SESSION["admin"], true);
} else {
$_SESSION["admin"] = 0;
}
// else
if (count($_POST)) {
// post: current action
if (isset($_POST["action"])) {
$_SESSION["action"] = cleanString($_POST["action"], true);
} else {
$_SESSION["action"] = "";
}
// else
// post: current password
if (isset($_POST["current_password"])) {
$_SESSION["current_password"] = cleanString($_POST["current_password"], true);
} else {
$_SESSION["current_password"] = "";
}
// else
} else {
if (count($_GET)) {
}
}
// else if
// session: nation_id
if (isset($_SESSION["nation_id"])) {
$_SESSION["nation_id"] = cleanString($_SESSION["nation_id"], true);
} else {
$_SESSION["nation_id"] = 0;
}
// else
// session: user_id
if (isset($_SESSION["user_id"])) {
$_SESSION["user_id"] = cleanString($_SESSION["user_id"], true);
} else {
$_SESSION["user_id"] = 0;
}
// else
// get info
//$_SESSION["userInfo"] = getUserInfo($getPage_connection2,$_SESSION["user_id"]);
//$_SESSION["nationInfo"] = getNationInfo($getPage_connection2,$_SESSION["nation_id"]);
}
示例12: readFromFile
function readFromFile($conn, $fname, $dryrun)
{
//This is my function to read from the csv file.
if ($dryrun) {
fwrite(STDOUT, "\n[DRYRUN: Reading from file (\"" . $fname . "\")]");
} else {
fwrite(STDOUT, "\n[Reading from file (\"" . $fname . "\") and Inserting into DB]");
}
$file = fopen($fname, "r");
//Open the file.
$firstLine = true;
//We don't need the first line (it's the headers).
while (!feof($file)) {
//While we are not at the end of the file...
if ($firstLine) {
$firstLine = false;
fgetcsv($file);
//Read in the first line and don't do anything with it.
} else {
$person = fgetcsv($file);
//Read in all details.
$name = cleanString($person[0]);
//Clean the string.
$surname = cleanString($person[1]);
//Clean the string.
$email = trim(strtolower($person[2]));
//trim trims whitespace, strtolower puts the string to lowercase.
$emailFlag = filter_var($email, FILTER_VALIDATE_EMAIL);
//Use php's function for checking valid emails.
if ($emailFlag) {
//If it's a valid email...
if (!$dryrun) {
//If we are not on a dry run, we have access to the DB.
insertRecord($conn, $name, $surname, $email);
//Call function to insert.
} else {
fwrite(STDOUT, "\nPerson: " . $name . " " . $surname . " (" . $email . ")");
}
} else {
//If email isn't valid, tell the user.
fwrite(STDOUT, "\n[ERROR]: The supplied email address, \"" . $email . "\", is invalid");
}
}
}
fclose($file);
//Close the file after we are done.
}
示例13: getGlobals_info
function getGlobals_info($getPage_connection2)
{
// session: admin
if (isset($_SESSION["admin"])) {
$_SESSION["admin"] = cleanString($_SESSION["admin"], true);
} else {
$_SESSION["admin"] = 0;
}
// else
if (count($_GET) > 1) {
// get: info id
if (isset($_GET["info_id"])) {
$_SESSION["info_id"] = cleanString($_GET["info_id"], true);
} else {
$_SESSION["info_id"] = 0;
}
// else
// get: section
if (isset($_GET["section"])) {
$_SESSION["section"] = cleanString($_GET["section"], true);
} else {
$_SESSION["section"] = 0;
}
// else
}
// if
// session: nation_id
if (isset($_SESSION["nation_id"])) {
$_SESSION["nation_id"] = cleanString($_SESSION["nation_id"], true);
} else {
$_SESSION["nation_id"] = 0;
}
// else
// session: user_id
if (isset($_SESSION["user_id"])) {
$_SESSION["user_id"] = cleanString($_SESSION["user_id"], true);
} else {
$_SESSION["user_id"] = 0;
}
// else
// get info
//$_SESSION["userInfo"] = getUserInfo($getPage_connection2,$_SESSION["user_id"]);
//$_SESSION["nationInfo"] = getNationInfo($getPage_connection2,$_SESSION["nation_id"]);
}
示例14: download
public function download()
{
$id = intval($_GET['id']);
$this->loadModel('schnippet');
$schnippet = new Schnippet();
$schnippet->load($id);
if ($schnippet->getMember('protected') == 'on' && (!isset($_SESSION[APP_SES . 'id']) || $_SESSION[APP_SES . 'id'] == 0)) {
$_SESSION[APP_SES . 'route'] = '/application/schnippets&m=edit&id=' . $_GET['id'];
gotoUrl('/?route=/users/users');
exit;
}
// remove all non-alphanumeric characters from title to make filename then replace whitespace with underscores
$title = cleanString($schnippet->getMember('title'));
// get file extension
$ext = getExt($schnippet->getMember('lang'));
header("Content-Type: plain/text");
header("Content-Disposition: Attachment; filename={$title}.{$ext}");
header("Pragma: no-cache");
echo $schnippet->getMember('code');
}
示例15: insert
public function insert()
{
$song_data = array('song_title' => cleanString($this->input->post('song_title')), 'song_year' => cleanString($this->input->post('song_year')), 'song_price' => cleanString($this->input->post('song_price')));
/* Insert the song and retrieve the song ID */
$song_id = $this->song_model->add($song_data);
$file_name = $song_data['song_title'];
/* Create directory for file upload */
$path = "data/music/songs/{$song_id}";
if (!is_dir($path)) {
mkdir($path, 755);
// Create the song directory
}
/* Load the Upload class */
$this->load->library('upload');
/* Upload the song cover */
$this->upload_cover($path);
/* Upload the file list */
$this->upload_songfile($file_name, $path);
/* Proceed to upload songs in the editor */
header("Location: " . base_url() . "admin/singles/");
}