Steven Macintyre wrote:
Heya,
Thanks for the reply ...
$articles = split("Section break", $mystring);
foreach ($articles as $value) {
$newsarray[] = split("<br>", $value);
}
print_r($newsarray);
foreach ($newsarray as $value1) {
echo "<b>".$value1[0]."</b>";
echo "<br><br>";
echo $value1[1];
this $value1[1]; does not exist.
Look at the array that it prints out in the first statement.
there is one array with-in another array, and each array has only one index
basically all you have is this.
$newsarray[0][0] = "Burli Web Server
Syntax error";
but you are trying to access this
$newsarray[0][1] // error, index does not exist
Include the source that you are using. Or give a link to the source.
}
Using that code ... the results are at www.kayafm.co.za/newst.php
I have no idea why the array is printed correctly - but my echoing of array
items is not
The stuff in bold SHOULD be on a new line ...
Can you take a look and offer me more advice?
S
-----Original Message-----
From: Jim Lucas [mailto:lists@xxxxxxxxx]
Sent: 09 February 2007 09:56 AM
To: Steven Macintyre
Subject: Re: array within array
Steven Macintyre wrote:
Hi all,
I have an array ($articles) that contains content in this format
Text<br>
More text
I am currently calling the creation of the array as such;
$articles = split("Section break", $mystring); <-- this works
NOW ... I need to split each item in the articles array into its
own array
(newsarray)
I have tried
Foreach ($articles as $value) {
$newsarray = split("<br", $value);
}
But this aint working ...
Can someone offer a better suggestion?
S
So, to put it all together
This ....
<plaintext><?php
$articles[] = "Text<br>More text";
$articles[] = "Text<br>More text<br>hi";
$articles[] = "Text<br>More text";
$articles[] = "Text<br>More text<br>hi";
$newsarray = array();
foreach ($articles as $value) {
# use this for splitting on every single <br> in them
$newsarray[] = split("<br>", $value);
# I would recommend this instead
$newsarray[] = split("<br>", $value, 2);
}
var_dump($newsarray);
?>
returns me this...
array(4) {
[0]=>
array(2) {
[0]=>
string(4) "Text"
[1]=>
string(9) "More text"
}
[1]=>
array(2) {
[0]=>
string(4) "Text"
[1]=>
string(17) "More text<br>hi"
}
[2]=>
array(2) {
[0]=>
string(4) "Text"
[1]=>
string(9) "More text"
}
[3]=>
array(2) {
[0]=>
string(4) "Text"
[1]=>
string(17) "More text<br>hi"
}
}
hope this helps
--
Enjoy,
Jim Lucas
Different eyes see different things. Different hearts beat on different
strings. But there are times for you and me when all such things agree.
- Rush
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php