$main_string="This is a test string <a href=http://www.plus2net.com>with a link</a> to plus2net";
if(stristr($main_string,"http://")){
echo "String contains a link or the text http:// inside it ";}
else {
echo "String does not contains a link or the text http:// inside it ";}
Archive for the ‘PHP.net’ Category
stristr – Searching inside a text string
Wednesday, March 3rd, 2010String dd-mm-yyyy convert to date yyyy-mm-dd
Saturday, February 27th, 2010<?php $date = "25-12-2010";//[something in US format: mm-dd-yy] $newdate = substr($date,6,4) . "-" . substr($date,3,2) . "-" . substr($date,0,2); print "\n=====\n".$newdate."\n===============\n"; ?>
strrev – reversed string
Saturday, February 27th, 2010
<?php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?>
UTF-8 connect to MySQL database
Monday, February 22nd, 2010
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_slovenian_ci'");
mysql_query("SET CHARACTER SET 'utf8';");
How to change the collation for all tables in a MySQL database to UTF-8?
Monday, February 22nd, 2010
<?php
$db = mysql_connect("localhost", "username", "pass");
if(!$db) echo "Cannot connect to the database - incorrect details";
mysql_select_db('myuser_mydbname'); $result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("ALTER TABLE $value COLLATE utf8_slovenian_ci");
}}
echo "The collation of your database has been successfully changed!";
?>
Convert string from Windows-1250 to UTF-8
Sunday, February 21st, 2010$string = iconv("CP1250", "UTF-8", $string);
PHP Calculating script execution time
Thursday, February 18th, 2010
<?php
$start = (float) array_sum(explode(' ',microtime()));
// put you code that wanted to render at here
$end = (float) array_sum(explode(' ',microtime()));
echo "Processing time: ". sprintf("%.4f", ($end-$start))." seconds";
?>
how to make symlink with cronjob or php
Saturday, January 16th, 2010CRONJOB
addd this in crontab -e
*/1 * * * * ln -s /home/user/public_html/drupal /home/user/public_html/site2
PHP
symlink ( string $target , string $link );
http://us3.php.net/manual/en/function.symlink.php
mysql_set_charset
Saturday, January 9th, 2010Dodaj kjer se povezuješ z bazo
PRIMER 1
mysql_query(“SET NAMES utf8″);
PRIMER 2$link1 = mysql_connect(‘localhost’,'user1′,’pass1′,TRUE);
mysql_selectdb(‘db1′,$link1);
mysql_set_charset(‘utf8′,$link1);
How many users are connected on http apache server
Friday, December 25th, 2009<?
if(isset($_GET['showsource'])) { highlight_file($_SERVER['SCRIPT_FILENAME']); die; }
function getIP() {
$ip=”";
if (getenv(“HTTP_CLIENT_IP”)) $ip = getenv(“HTTP_CLIENT_IP”);
else if(getenv(“HTTP_X_FORWARDED_FOR”)) $ip = getenv(“HTTP_X_FORWARDED_FOR”);
else if(getenv(“REMOTE_ADDR”)) $ip = getenv(“REMOTE_ADDR”);
else $ip = “”;
return $ip;
}
function howManyIps() {
$filename = “./howmanyip.log”;
$seconds = 300;
$yourIP = getIP();
if (file_exists($filename.”.lock”)) $readonly = true; else $readonly=false;
$count = 0;
//lock the file
if (!$readonly) $fpLock = fopen($filename.”.lock”, “w”);
//read data ips
$fp = @fopen($filename, “r”);
$arIPS=explode (“\n”, @fread($fp,filesize($filename)) );
@fclose($fp);
//if file is locked get out
if ($readonly) return count($arIPS);
$s = “”;
$already=false;
//update data and search user ip
for ($i=0;$i<count($arIPS);$i++) {
$arData= explode (” “, $arIPS[$i]);
//update your user timer
if ($yourIP==$arData[0]) {
$already=true;
$arData[1]=time();
}
// check if user is old
if ( time()- (integer)$arData[1] < $seconds ){
$s.=$arData[0].” “.$arData[1].”\n”;
$count++;
}
}
if (!$already) {
//your user is new, add it to the list
$s.=$yourIP.” “.time().”\n”;
$count++;
}
//save the list
$fp = fopen($filename, “w”);
fwrite($fp,$s);
fclose($fp);
//remove thr lock
fclose($fpLock);
unlink($filename.”.lock”);
return $count;
}
echo howManyIps().” connected.”;
?>
Vir: http://www.barattalo.it/category/php/page/3/



![Validate my RSS feed [Valid RSS]](wp-content/uploads/valid-rss.png)


