Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explode Question 1

Status
Not open for further replies.

MrPantsTm

Programmer
Joined
Jan 22, 2004
Messages
71
Location
US
I have text in a MySQL database. When it goes in there are paragraphs. When it comes out, there are none. I figure I'd use explode to seperate the paragraphs when it is read out of the database. My question is what I would use as a point to explode at. e.g. a <br>
thanks for any suggestions.
 
I have the following suspicion:

1. You store the text in the table.
2. You get it out and print it to HTML.

In that case be aware how HTML handles whitespace. The paragraphs are probably delineated (look at the source). You might consider the nl2br() function before displaying the text.
 
sleipnir214 - I assume an EOL.

DRJ478 - gold. Thats exactly what I needed to format the output.


However, now I have another related issue. In another page I'm going to have a field where there are related people working on the project. ATM, it's going to return a list of who is on the task. i.e it would return: Joe Smith <space> Joe Smith2 <space> etc etc. What I'm going to want to do is take those individual names and make them into links on the fly so I'll need to break the names up into individual chunks. I'd rather not break down and force users to use a , in between the names so that I can explode on that although since there will be spaces between the first and last names, I won't be able to break on spaces either. Any suggestions?

Thanks for the quick response to the last question.
 
Regular expression - given that everyone just inputs firstname lastname. Middlenames, double last names would screw it up.

How do you retrieve tha names? Where does the list come from?
 
mysql database with a select statement. personally I'd like it if they could enter the user id # but I doubt thats viable ;)
 
When you retrieve the names from the MySQL source I suppose every person has their own record. If that's the case instead of concatenating the names in a string add them to an array to begin with.
Code:
while ($row = mysql_fetch_assoc($result)){
   # add to array
   $personnel[] = $row['firstname'].' '.$row['lastname'];
}
L:ater you can implode() to display as a list and use <br /> as a delimiter.
 
explode() and different versions of php?

I am running this code on version 4.3.4

This code takes a range of years e.g. 1980-85 and inserts into the database 80,81,82,83,84,85

$yr=explode(&quot;-&quot;, $years);
if($yr)
{
$left=substr($yr[0],-2);
$right=substr($yr[1],-2);
$var=range(&quot;$left&quot;,&quot;$right&quot;);
for($i=0; $i < $right; $i++)
$years=implode(&quot;,&quot;, $var);

}//end if

I then use the variable $years in a database.

The code works perfect on version 4.3.4 but when I run it on version 4.2.1 it does not work

I only get a singe digit. In this case it would just be an 8

Does anybody know why??

Thanks


 
No idea. However, use a regular expression instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top