michel-angelo
asked on
Striping String
Hi Experts !
Here is one of the field from the database :
<th>Transmission</th>
<td>4 Speed Automatic with Overdrive</td>
</tr>
<tr>
<th>Drive Type</th>
<td>4 wheel drive - rear</td>
</tr>
<tr>
<th>Fuel Type</th>
<td>Gasoline</td>
The following :
$row['cont'] = strip_tags($row['cont']);
$row['cont'] = str_replace('\n',' ',$row['cont']);
$row['cont'] = str_replace('\r',' ',$row['cont']);
$row['cont'] = trim($row['cont']);
seems to generates the same string...without the tags (but the spaces, lines...) while I would like the string to be ONE line, so that any closing tag will become a space to separate the content nicely.
All I have succeeded so far is to have my csv file looking like ^%$^$@#@.
PLEASE HELP
Here is one of the field from the database :
<th>Transmission</th>
<td>4 Speed Automatic with Overdrive</td>
</tr>
<tr>
<th>Drive Type</th>
<td>4 wheel drive - rear</td>
</tr>
<tr>
<th>Fuel Type</th>
<td>Gasoline</td>
The following :
$row['cont'] = strip_tags($row['cont']);
$row['cont'] = str_replace('\n',' ',$row['cont']);
$row['cont'] = str_replace('\r',' ',$row['cont']);
$row['cont'] = trim($row['cont']);
seems to generates the same string...without the tags (but the spaces, lines...) while I would like the string to be ONE line, so that any closing tag will become a space to separate the content nicely.
All I have succeeded so far is to have my csv file looking like ^%$^$@#@.
PLEASE HELP
ASKER
Now what I have is something like this (not same string as above but you've got the picture):
Body Style Coupe Mileage Unlisted Exterior Color Rally Yel Interior Color Ebony Lth Engine 4 Cylinder Supercharg Transmission 5 Speed Manual Drive Type 2 wheel drive - front Fuel Type Gasoline
Strangely enough what AngelIII provided me with did not really modify anything at all .. but the execution time went up by 30%.
Now if I can just eliminate the extra spaces .. I ll be in business.
Maybe a regex replace that would take out all extra spaces ?
It s late .. I am now BEGGING for your help ! :)
Body Style Coupe Mileage Unlisted Exterior Color Rally Yel Interior Color Ebony Lth Engine 4 Cylinder Supercharg Transmission 5 Speed Manual Drive Type 2 wheel drive - front Fuel Type Gasoline
Strangely enough what AngelIII provided me with did not really modify anything at all .. but the execution time went up by 30%.
Now if I can just eliminate the extra spaces .. I ll be in business.
Maybe a regex replace that would take out all extra spaces ?
It s late .. I am now BEGGING for your help ! :)
ASKER
would something like $t= str_replace(" ","",$t) work ?
ASKER
Anybody ?
the following might work:
$t= str_replace(" "," ",$t);
$t= str_replace(" "," ",$t);
ASKER
nope I still have plenty of spaces, it is like the string is not being taken as a whole but a succession of lines, meaning the change (such as str_replace) would take place only on the first line of the string.
then it's not a normal space, but other characters...
I assume you put the str_replace in the following order...
$t = strip_tags($row['cont']);
$t = str_replace("\n"," ",$t);
$t = str_replace("\r"," ",$t);
$t= str_replace(" "," ",$t);
$t = trim($t);
I assume you put the str_replace in the following order...
$t = strip_tags($row['cont']);
$t = str_replace("\n"," ",$t);
$t = str_replace("\r"," ",$t);
$t= str_replace(" "," ",$t);
$t = trim($t);
ASKER
I also replaced by a space .. and this is what I have so far :
$t = strip_tags($row['cont']);
$t = str_replace("\n"," ",$t);
$t = str_replace("\r"," ",$t);
$t = str_replace(" "," ",$t);
$t = str_replace(",",";",$t);
$t = str_replace("'"," ",$t);
$t = str_replace(" ","",$t);
$t = trim($t);
In that order.
$t = strip_tags($row['cont']);
$t = str_replace("\n"," ",$t);
$t = str_replace("\r"," ",$t);
$t = str_replace(" "," ",$t);
$t = str_replace(",",";",$t);
$t = str_replace("'"," ",$t);
$t = str_replace(" ","",$t);
$t = trim($t);
In that order.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
$t = strip_tags($row['cont']);
$t = preg_replace('/[\n\r \']/', ' ', $t);
$t = str_replace(" "," ",$t);
$t = str_replace(",",";",$t);
$t = trim($t);
$t = strip_tags($row['cont']);
$t = preg_replace('/[\n\r \']/', ' ', $t);
$t = str_replace(" "," ",$t);
$t = str_replace(",",";",$t);
$t = trim($t);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works :)
Thanks to the two of you !
Thanks to the two of you !
You're welcome :)
$t = strip_tags($row['cont']);
$t = str_replace("\n"," ",$t);
$t = str_replace("\r"," ",$t);
$t = trim(t);