0

I've created a simple query to create a list of dates and descriptions from my calendar database. The idea is that I have a PHP webpage that show a text list that I can quickly copy and paste into an email or text message. My problem is that, although the text shows up correctly on the web page, when I paste the info into a text editor (Word, email, whatever) I'm getting tabs between each column.

How can I format the text in PHP so that it pastes correctly?

This is my code:-

if(mysql_num_rows($AvDates) > 0){
    ?>
    <ul>
        <?php
            while ($row_AvDates = mysql_fetch_assoc($AvDates)){ 
                ?>
                <li>
                    <?php echo htmlentities($row_AvDates['Month']);?>
                    <?php echo "-";?>
                    <?php echo htmlentities ($row_AvDates['the_days']);?>
                </li> 
                <?php
            }      
        ?>
     </ul>
<?php
}
?>

This gives me output that looks correct, but pastes like this...

(Month[tab]"-"[tab] Dates)

How do I loose the tabs?

1
  • 2
    The tabs you're seeing are part of the HTML output since you're closing php tags and outputting HTML (with hidden tab chars). Echo out everything on one line or don't close the php tag. Commented Jan 20, 2014 at 12:53

4 Answers 4

1

You're closing php and letting the HTML output be rendered. See tab chars below:

    [tab]<li><?php echo htmlentities($row_AvDates['Month']);?>
    [tab]<?php echo "-";?>
    [tab]<?php echo htmlentities ($row_AvDates['the_days']);?></li> 

Solution:

<?php echo htmlentities($row_AvDates['Month']) . '-' . htmlentities ($row_AvDates['the_days']); ?>
Sign up to request clarification or add additional context in comments.

Comments

1

Darren.

Try to use this code, it should solve your problem:

<?php if (mysql_num_rows($AvDates) > 0) : ?>
    <ul>
        <?php while ($row_AvDates = mysql_fetch_assoc($AvDates)) : ?>
            <li><?php echo htmlentities($row_AvDates['Month'])."-".htmlentities ($row_AvDates['the_days']);?></li>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>

Hope it helps.

1 Comment

Why did I get a minus?
1

you can have the whole output in one single like this

<?php echo htmlentities($row_AvDates['Month']) . '-' . htmlentities($row_AvDates['the_days']);?>

instead of separate php tags

Comments

0

If you want to separate code across multiple lines, not all code in one line:

if(mysql_num_rows($AvDates) > 0){
?>
<ul>
<?php

    while ($row_AvDates = mysql_fetch_assoc($AvDates)){ 
 ?>


        <li><?php 
            echo htmlentities($row_AvDates['Month']);
            echo "-";
            echo htmlentities($row_AvDates['the_days']);
        ?></li> 
<?php
    }      
?>
</ul>

<?php
}
?>

1 Comment

i think he/she wants to loose the tabs instead of introducing them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.