Archive for the ‘PHP’ Category

Read And Write Image PHP

Thursday, July 17th, 2008

function save_image($url,$filename){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen($filename,’w');
fwrite($fp, $rawdata);
fclose($fp);
}

When you run this function and get error  call undefined function curl_init  you must enable curl php extension  in php.ini file.

Cannot modify header information

Monday, July 7th, 2008

I’m have php error when  I user header(”Location:index.php”);  I’m google to take amswer

Originally Posted by kenmcd

The “headers already sent” error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).

Have you recently edited any files?

 

Is good.

Source : http://forum.mamboserver.com/showpost.php?p=265568&postcount=10

Call to undefined function mysql_connect

Tuesday, May 27th, 2008

To day I’m install php5 , apache and mysql, I dowload “php-5.2.6-Win32.zip”  installer packet and apache “apache_2.2.8-win32-x86-openssl-0.9.8g.msi” and then I’m download mysql server

1. Install apache  apache_2.2.8-win32-x86-openssl-0.9.8g.msi

2. Extract php-5.2.6-Win32.zip to c:\php\php5 ( I create new dir php5 contain php5 only).

3. Rename php.ini.dst to php.ini in c:\php\php5 then cut to c:\windows

4. Copy libmysql.dll in c:\php\php5 to c:windows\system32

5. Edit httpd.conf in  C:\apache2.2\conf\ add this line

# ==== Load Module PHP5 ======
LoadModule php5_module “C:/php5/php5apache2_2.dll”
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

6. Restart apache and create php.info() for test php installation.

7. Install Mysql Server and create file for test db.

<?php
$dbhost=”localhost”;
$dbuser=”root”;
$dbpassword=”1234″;
mysql_connect($dbhost,$dbuser,$dbpassword);
echo “Test MySQL”;
?>

After run this file error occur “Fatal error: Call to undefined function mysql_connect() in C:\apache2.2\htdocs\testDB.php on line 5

I’m back to php.ini and uncomment

extension=php_mysql.dll

You might also need to configure the extension_dir variable.

extension_dir = “C:\php\php5\ext”

Restart apache and run  execute file again

How to strip html tag

Thursday, May 22nd, 2008

To day I’m write php code for get content from ezinearticle.com and post it to my blogger via gmail. after I use file_get_contents I had a html code of content then I must strip html tag out and cut out some body I try to search for google and found at php.net can help me.

<?php
$text
= ‘<p>Test paragraph.</p><!– Comment –> <a href=”#fragment”>Other text</a>’;
echo
strip_tags($text);
echo
“\n”;

// Allow <p> and <a>
echo strip_tags($text, ‘<p><a>’);
?>

In function can strip another <p>, <a>.

Write File PHP

Thursday, May 22nd, 2008

All language had function that can call in case write file to local directory if PHP use like code

$fo = fopen(’title.txt’,'w’);
fwrite($fo,’some text’);
fclose($fo);

$fo is a instance of fopen(’file name’,'mode write or read’).