I have a loop that successfully shows account numbers. Some of these numbers were saved into the db with an "@" prepended. I would like to strip the "@" sign from the displayed results. I've seen plenty of solutions for a simple echo that accomplishes this by using trim
, preg_replace
, etc, but nothing within a for
loop. Any ideas?
My current code (not including an attempted solution):
<?php
$query = sprintf("SELECT banner_id FROM tablename") or die(mysql_error());
$result = mysql_query($query, $dblink) or die(mysql_error());
$i = 0;
if($result){
while($row = mysql_fetch_array($result)){
$banner_id[$i] = $row['banner_id'];
$i++;
}
}
?>
<html><body>
<ul>
<?php
for($x=0; $x < mysql_num_rows($result); $x++) {
echo "<li>{$banner_id[$x]}</li>\n";
}
?>
</ul>
</body></html>
Current Output:
Desired Output:
I feel like this should be easy, but I can't find anything that works. Thanks for any help you can offer!
I can't get why you think you can't use trim()
inside a for
loop.
<?php
for($x=0; $x < mysql_num_rows($result); $x++) {
$out = ltrim($banner_id[$x], '@');
echo "<li>$out</li>\n";
}
?>