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


Loading bits of files with PHP





Dougie1
So I know basic file loading in php and know that you can filter it so that only certain lines are displayed but can you filter it so that only certain parts of a line are submitted. Say I wanted to echo the whole line excluding the first and last word, or the whole line excluding the word and or something like that. I don't know if it is possible but it would be great if you could help! Thanks

Also how would I go about missing out certain characters in a file or when I am echoing anything. Say I didn't want the letter "T" to appear what would I do? Thanks and I am sorry that this is a bit specific.
hexkid
Possible solutions below

Dougie1 wrote:
echo the whole line excluding the first and last word
Code:
<?php
$line = 'The quick brown fox jumps over the lazy dog.';
$words = explode(' ', $line);
unset($words[count($words)-1]);
unset($words[0]);
echo implode(' ', $words);
?>


Dougie1 wrote:
the whole line excluding the word and
Code:
<?php
$line = 'I saw John and Mary and their dog yesterday.';
echo str_replace(' and', '', $line);
?>


Dougie1 wrote:
Say I didn't want the letter "T" to appear what would I do?
Code:
<?php
$line = 'Twenty Three';
echo str_replace('T', '', $line);
?>
Dougie1
Thanks so much hexkid that has been really useful.

Is there a way that I could delete the first say ten characters or last 10 from a statement though. I have searched PHP net and could not find anything. Thanks. Smile
hexkid
Dougie1 wrote:
Is there a way that I could delete the first say ten characters or last 10 from a statement though.

Code:
<?php
$line = 'abcdefghijklmnopqrstuvwxyz';
echo substr($line, 0, -10), "<br>\n";
echo substr($line, 10), "<br>\n";
echo substr($line, 10, -10), "<br>\n";
?>
Related topics
Web Reporting - AWSTATS
Putting a Banner in php -nuke
[UPDATE] zip support
PHP, MySQL and Flash
Need help with php script
[FLASH] Problem with loading vars from php
CSS/HTML
The Curse of Kaumaha (a platform adventure)
MORE smf help needed!!!
Creating a .txt file
Co-Op in HL2?
PHP vs J2EE
Support for retrieving external files?
PHP-Fusion | An Open Source CMS | PHP & MySQL Based
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.