Jump to content

php and html on different lines


russthebarber

Recommended Posts

i am having to use a javascript function to make an html form 'submit' button look like a link. this is working fine on its own. the problem is when i combine this with some php (first) its putting the link on a separate line. can anyone see where the problem is in my code.

 

if(strlen($str) > $chars)

    {echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; ?>

 

<a href="javascript:getsupport('<? echo $row ['id']; ?>')"><div style="color:#FFFFFF;  font-size:9px">more</div></a>

 

///end of relevant code. there is more code at the bottom if this is not clear.

 

i'm getting this:

 

bla bla bla bla bla...

more

 

i should be getting this:

 

bla bla bla bla bla...more

 

///here's some more of the code

 

<table border="0" align="left" cellpadding="0" cellspacing="0" height="122" width="494" background="img/bgbox2_494x1.jpg">

<tr>

<td height="11"></td>

</tr>

 

<form name="supportform" method="post" action="newsmore.php">

<input type="hidden" name="id" />

 

<?

 

$counter="0";

 

while($row = mysql_fetch_array($result))

 

{

$counter=$counter+1;

 

if($counter == "1") {$bg="img/bgbox2_494x1.jpg";}

if($counter == "2") {$bg="img/bgbox2_494x1b.jpg";}

if($counter == "3") {$bg="img/bgbox2_494x1.jpg";}

if($counter == "4") {$bg="img/bgbox2_494x1b.jpg";}

if($counter == "5") {$bg="img/bgbox2_494x1.jpg";}

 

?>

 

 

  <tr>

    <td background="<? print("$bg"); ?>" height="20"><div style="color:#FFFFFF; margin-left:15px; margin-right:15px; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:9px">

 

<? $str = $row['entry_date'] . $spacer . $row['maintext'];

 

if(strlen($str) > $chars)

    {echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; ?>

 

 

 

<a href="javascript:getsupport('<? echo $row ['id']; ?>')"><div style="color:#FFFFFF;  font-size:9px">more</div></a>

 

 

<?

}

 

 

else

{echo $str . '... <a href="#">more</a>';}

 

?>

 

</div>

</td>

</tr>

 

 

</form>

 

 

 

 

<?

}

?>

 

  <tr><td height="11"></td></tr>

</table>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/186184-php-and-html-on-different-lines/
Share on other sites

Let's try one more thing...

 

<table border="0" align="left" cellpadding="0" cellspacing="0" height="122" width="494" background="img/bgbox2_494x1.jpg">
   <tr>
      <td height="11"></td>
   </tr>
   
         <form name="supportform" method="post" action="newsmore.php">
<input type="hidden" name="id" />
   
   <?
   
$counter="0";

   while($row = mysql_fetch_array($result))

{
$counter=$counter+1;

if($counter == "1") {$bg="img/bgbox2_494x1.jpg";}
if($counter == "2") {$bg="img/bgbox2_494x1b.jpg";}
if($counter == "3") {$bg="img/bgbox2_494x1.jpg";}
if($counter == "4") {$bg="img/bgbox2_494x1b.jpg";}
if($counter == "5") {$bg="img/bgbox2_494x1.jpg";}

?>


      <tr>
       <td background="<? print("$bg"); ?>" height="20"><div style="color:#FFFFFF; margin-left:15px; margin-right:15px; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:9px">
   
   <? $str = $row['entry_date'] . $spacer . $row['maintext'];
   
if(strlen($str) > $chars)   {
    echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; ?>

   <div style="color:#FFFFFF;  font-size:9px">
   <a href="javascript:getsupport('<? echo $row ['id']; ?>')">
   more
   </a>
   </div>   
   

<?
}

else
    {echo $str . '... <a href="#">more</a>';}   
   
?>
   
   </div>
      </td>
   </tr>
</form>   
   
<?
}
?>
   
  <tr><td height="11"></td></tr>
</table>


The only other thing I can see is this:

 

echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; ?>

 

The wordwrap() function defaults to 75 characters, I think, before adding a \n. Not sure, though. Hard to tell without knowing how $chars is defined.

On the output line:

 

echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; ?>

 

Have you tried to capture the actual output to check for odd newlines and exact HTML code? Sorta like:

 

$array = array();
$array[0] = end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...';
echo end(array_reverse(explode("\n", wordwrap($str, $chars)))) . ' ...'; 
?>
<!-- hidden 
<? print_r($array); ?>
-->

 

If you could, would you post the print_r output?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.