FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


substr alternative... And Writing To File Problems.





Dougie1
Is there an alternative for outputting the first three characters of the text if you do not know the length of the text apart from counting the characters then bla bla bla....

If not I will just do it the long way. Thanks.

Please see the bottom for more.
sonam
Code:
$name = "something_long";
echo $name['0'] . $name['1'] . $name['2'];


If I good understand what do you want.

Sonam
Dougie1
Thanks for the help sonam. Yeah I think that is right (haven't checked yet). Sorry I wasn't very understandable.

Also one last question. I am trying to write text to a file and it is not working.
Code:
    $write = "
    $_POST['1']
    $_POST['2']
    $_POST['3']
    $_POST['4']
    $_POST['5'] ";

fwrite($file, $write);


Why is this??
sonam
Quote:
Sorry I wasn't very understandable.


AAAAH, my English is not very well. Embarassed

You cannot write in file before you open it.
Code:
   $write = "something\n";
   $file = fopen("someFolder/someFile.txt", "wb");
   fwrite($file, $write);
   fclose($file);


Be carefull with "wb" that comand will delete all existing entries in file. If you want extend your data then you must use different comand. Here is list of all:
http://hr.php.net/manual/en/function.fopen.php

Sonam
MrBlueSky
Dougie1 wrote:
Thanks for the help sonam. Yeah I think that is right (haven't checked yet). Sorry I wasn't very understandable.

Also one last question. I am trying to write text to a file and it is not working.
Code:
    $write = "
    $_POST['1']
    $_POST['2']
    $_POST['3']
    $_POST['4']
    $_POST['5'] ";

fwrite($file, $write);


Why is this??


You can't use array references in strings. Use

Code:
 
$write = $_POST['1'] . $_POST['2'] . $_POST['3'] . $_POST['4']. $_POST['5'] ;

fwrite($file, $write);


instead.
kv
or

Code:


$write = "{$_POST['1'] }{$_POST['2'] }{ $_POST['3'] }{ $_POST['4']} {$_POST['5'] }";

fwrite($file, $write);

Related topics
File upload with PHP, Build an upload database for your site
Okay, I'm done trying to use CSS for layout.
Flash Alternative
Problem with my password
How To : Improve Your PHP Programming
PHP Tutorials
writing COM components in Perl
Any writers here
Communism ?
New Created Accounts
Removing tables, even for tabular data
PHP Form Question
File Permissions Writing/Reading
Problem with CSS menu
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.