$rowB['charge']= preg_replace( $rowB['charge'] =  1||0||-1, " ", $rowB['charge']);

Three things i want to do:
1. Is there a way replace the numbers -1, 0 and 1 with empty spaces but still have all the other numbers still show up i.e 2-9 & "-2" - "-9"? My preg_replace variations either does all or none.
2. I want to strip all negative numbers of their negative signs and only have absolutes i.e -2 to 2.
3. I seriously need code for doing subscripts or supscripts in php? I can do it in html.

Recommended Answers

All 4 Replies

Can you show some sample data, so we can see what is going in, and how it should look after the replace?

$rowA = mysql_fetch_array($resultA, MYSQL_BOTH) or die(mysql_error());
$rowB = mysql_fetch_array($resultB, MYSQL_BOTH) or die(mysql_error());

  if ($rowA['charge'] > 0 )
   {         
             $rowA['charge']= preg_replace( 1, " ", $rowA['charge']);

             $rowB['charge']= preg_replace( $rowB['charge'] =  1||0||-1, " ", $rowB['charge']);



        ?> <tr><td> <? echo" '". $rowA['symbol'] . $rowB['charge']. $rowB['symbol'] .
         $rowA['charge'] ."'  "; ?> </td></tr> <?  
    }

What i really want this to do is get those values in the array. if the value is 1 or -1, then i don't want it echoed out, nor its charge. If it is more than 1 then i want it echoed out. Also if it is less than -1 i.e -2 to -9, then i want only numbers echoed out minus the -ve sign.

Also if anyone knows how to write subscripts in php code(numbers or letters)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.