473,508 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

explode

Hi All, I'm trying to use explode to separate the result of a textual
file, but it explode me only the first row.

the foo.txt is
pippo pluto
pluto pippo
pippo pippo
....

I use this script found in http://it2.php.net/manual/en/function.explode.php

$pizza = "/var/www/foo.txt";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

Mar 24 '07 #1
4 2657
sorry.. this is the correct one:

$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br />\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br />\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}

it echoes only the first line of the file

pippo pluto

Mar 24 '07 #2
On 24 Mar, 09:39, "Davide" <davide.papa...@gmail.comwrote:
sorry.. this is the correct one:

$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br />\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br />\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}

it echoes only the first line of the file

pippo pluto
Ok.. I solved...
It was the space in <br />

$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br>\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br>\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}

Mar 24 '07 #3
Davide wrote:
On 24 Mar, 09:39, "Davide" <davide.papa...@gmail.comwrote:
>sorry.. this is the correct one:

$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br />\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br />\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}

it echoes only the first line of the file

pippo pluto

Ok.. I solved...
It was the space in <br />

$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br>\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br>\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}
Well, you seemed to solved it all by yourself. :-)
Now have a nice pizza. :P

Regards,
Erwin Moller
Mar 26 '07 #4
On 26 Mar, 14:05, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Davide wrote:
On 24 Mar, 09:39, "Davide" <davide.papa...@gmail.comwrote:
sorry.. this is the correct one:
$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br />\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br />\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}
it echoes only the first line of the file
pippo pluto
Ok.. I solved...
It was the space in <br />
$pizza = "/var/www/foo.txt";
$lines = file('/var/www/foo.txt');
foreach ($lines as $line_num =$line) {
htmlspecialchars($line) . "<br>\n";
$pieces = explode(" ", htmlspecialchars($line) . "<br>\n");
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}

Well, you seemed to solved it all by yourself. :-)
Now have a nice pizza. :P

Regards,
Erwin Moller
Yes! Just RTFM carefully :)
Hope it helps someone...
:P

Mar 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5047
by: Rob Gudgeon | last post by:
Hi Is it possible to explode a string into an array using more than one separator? I have database records that contain several values, mostly split by semi-colons but some older records are...
6
23916
by: William Krick | last post by:
I have a string containing concatenated ascii "records" that are each terminated by '\n'. For testing purposes, I construct sample data like this... $mystring =...
4
10170
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
12
2891
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
3445
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
1953
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
8
1945
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
3275
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
8
5454
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.