Senareo;
I've just had to upload a php website to an IIS 6 web server. Amazingly, everything worked apart from the ability to send email. I informed the hosing provider and they set up a different SMTP server to send email from. I now needed to tell my website where the different smtp server resided.
The Solution
I used the ini_set command in php. It allowed me to override the default php setup, and add it to a config file. I believe this can also be achieved by .htaccess, however having the setting in a config file in php suited me better.
<?
ini_set('SMTP','yourmailserver.com');
?>
Note: The ideal solutions would have been to have php.ini changed, but this solution works for now.
Monday, 15 November 2010
Friday, 2 April 2010
php exchange rate
Making multi currency websites can be a complete nightmare. Exchange rates change at a moments notice and it can be a constant struggle to keep yourself from losing money if one of the many markets crash.
Therefore I did a little bit of research and found you can get a rough idea of exchange rates by using yahoo finance. Yahoo provide a csv download from their site with live data. It's probably not as reliable as a feed from xe.com, but it's free and gives you a good indication of the exchange rate.
Here's a funscion i've made fo get this data;
function fget_exchange_rate($into, $infrom='GBP'){
$lcsv = file_get_contents('http://download.finance.yahoo.com/d/quotes.csv?s='.$infrom.$into.'=X&f=sl1d1t1ba&e=.csv');
$la = split(',',str_replace('"','',$lcsv));
if($la[1] != '') return $la[1];
return false;
}
echo('US $'.fget_exchange_rate('USD').'
');
echo('AU $'.fget_exchange_rate('AUD').'
');
echo('Euro '.fget_exchange_rate('EUR').'
');
echo('Japan '.fget_exchange_rate(JPY).'
');
You could add this to an automatic script to update the prices on your site daily. However, please be aware that you still need to keep an eye on things just incase you encounter problems.
Therefore I did a little bit of research and found you can get a rough idea of exchange rates by using yahoo finance. Yahoo provide a csv download from their site with live data. It's probably not as reliable as a feed from xe.com, but it's free and gives you a good indication of the exchange rate.
Here's a funscion i've made fo get this data;
function fget_exchange_rate($into, $infrom='GBP'){
$lcsv = file_get_contents('http://download.finance.yahoo.com/d/quotes.csv?s='.$infrom.$into.'=X&f=sl1d1t1ba&e=.csv');
$la = split(',',str_replace('"','',$lcsv));
if($la[1] != '') return $la[1];
return false;
}
echo('US $'.fget_exchange_rate('USD').'
');
echo('AU $'.fget_exchange_rate('AUD').'
');
echo('Euro '.fget_exchange_rate('EUR').'
');
echo('Japan '.fget_exchange_rate(JPY).'
');
You could add this to an automatic script to update the prices on your site daily. However, please be aware that you still need to keep an eye on things just incase you encounter problems.
Friday, 19 February 2010
Vi delete line if search does not exist
Right, if you have ever had to scroll through an endless text file looking for the needle in a haystack, there is a simpler way using the vi editor. Using vi, You can use a simple search and delete command to search the file and delete lines where a phrase doesn;t exist, like so;
:g!/text to look for/d
The example above searches all lines for text containing 'text to look for' and deletes the line if the text does not exist.
You could do the opposit and delete lines where the text exists like so;
:g/text to look for/d
:g!/text to look for/d
The example above searches all lines for text containing 'text to look for' and deletes the line if the text does not exist.
You could do the opposit and delete lines where the text exists like so;
:g/text to look for/d
Tuesday, 16 February 2010
json_decode Fatal error: Cannot use object of type stdClass as array
You may receive the following error when encoding and decoding information using json in php
Fatal error: Cannot use object of type stdClass as array
When using json_decode, information is by default converted into an object. You need to use the function get_object_vars to convert the object into an array, like so;
$new_data = get_object_vars(json_decode($data));
print_r($new_data);
?>
Fatal error: Cannot use object of type stdClass as array
When using json_decode, information is by default converted into an object. You need to use the function get_object_vars to convert the object into an array, like so;
$new_data = get_object_vars(json_decode($data));
print_r($new_data);
?>
Subscribe to:
Posts (Atom)