Archive

Archive for the ‘php_mysql’ Category

php curl 2 & http build query

October 24th, 2008 No comments

http_build_query

//extract data from the post
extract($_POST);

//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
						'lname'=>urlencode($last_name),
						'fname'=>urlencode($first_name),
						'title'=>urlencode($title),
						'company'=>urlencode($institution),
						'age'=>urlencode($age),
						'email'=>urlencode($email),
						'phone'=>urlencode($phone)
				);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
Categories: php_mysql Tags:

Convert MySQL date to UNIX timestamp

October 20th, 2008 No comments
< ?php
// from MySQL to UNIX timestamp
function convert_datetime($str)
{

list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

return $timestamp;
}
?> 
Categories: php_mysql Tags:

Pretvorba iz windows-1250 v UTF-8

February 2nd, 2008 No comments

iconv( “windows-1250″,”UTF-8″,$vsebina);

Categories: php_mysql Tags:

Get Country From IP

January 29th, 2008 No comments
$country = trim(strip_tags(file_get_contents('http://www.melissadata.com/lookups/iplocation.asp?ipaddress='.$ip)));
$start = strpos($stringData,"State or Region");
$stop = strpos($stringData,"Country");
$country = substr($stringData,$start+39,$stop - $start-17);
Categories: php_mysql, Web Tags:

Get Data From MySQL Database

October 8th, 2007 No comments

< ?php
include 'config.php';
include 'opendb.php';

$query = 'SELECT * FROM news WHERE id="'.mysql_real_escape_string($_GET['id']).'"';
$result = mysql_query($query);

echo mysql_result($result, 2); // outputs third employee's name

while($row = mysql_fetch_assoc($result))
{
    echo "Name :{$row['name']} <br>" .
         "Subject : {$row['subject']} <br />" .
         "Message : {$row['message']} <br /><br />";
}

UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value

include 'closedb.php';
?>
Categories: php_mysql Tags:

WordPress Code Highlight

October 4th, 2007 No comments

In da, končno sem našel odlični “barvalnik” programske kode, prav takšnega, kot sem si ga zamislil!
Code Highlighter plugin
Demo:

< ?php
$user="xxxxxx";
$password="yyyyyy";
$database="my_database";
@mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
@mysql_query("SET NAMES utf8"); //reši nekatere probleme pri šumnikih
?>
Categories: php_mysql Tags: , ,
17043 pages viewed, 0 today
11075 visits, 0 today
FireStats icon Powered by FireStats