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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Echoing a record minus a particular character 2

Status
Not open for further replies.

meeble3

Programmer
Nov 8, 2004
52
GB
Hello,

When I pull a record from the database, it is a word, (varchar) and I echo it to the page.

Sometimes the word is like this - 'hello' and sometimes like this 'hello3' or 'hel3lo'.

Is there a way to say if any record contains 3 wherever it is in the word, just to print the word without the 3 so it always says 'hello'?

Cheers

James
 
Thanks, but doesn't do anything.

My line is:

echo str_replace( "3", "", $myrow[0] );

but it doesn't change anything. Any ideas?

Cheers

James
 
are you getting any errors? what is the value in $myrow[0]?

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
That seems strange. Let's see the code that you use to generate the output (more than the echo statement).
Cheers.
 
The code is...

$result = mysql_query("SELECT DISTINCT area from centres where towncity = 'London' order by area",$db);

while ($myrow = mysql_fetch_row($result)) {

echo str_replace( "3", "", $myrow[0] );

echo"<option><span class=\"formfont\">$myrow[0]</span></option>";

}
 
The first echo statement should print the replaced value into the output. However, it doesn't change the content of the record data.
Code:
$result = mysql_query("SELECT DISTINCT area from centres where towncity = 'London' order by area",$db);

while ($myrow = mysql_fetch_row($result)) {

   echo"<option><span class=\"formfont\">".str_replace( "3", "", $myrow[0] )."</span></option>\n";
}

You either need to assign the replaced value to the row or use the function on the output as shown above. You code just echos the original content og the row.
 
you can also use regex to do this as well, it may be more viable if the number changes...

$var = eregi_replace("[[:digit:]]","",$da_result);

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top