简体   繁体   中英

how can I use substr within a HTML Div in a php echo

How can i modify the echo to allow the substr in a curly bracket. I have added other columns from the table to the array but I cannot seem to fetch the first 40 characters using the substr in an echo.

$query = "SELECT * FROM events";

$events = mysql_query($query,$dbc);

while ($eventlist = mysql_fetch_array($events))
{

 echo "<div id=\"container7\">
 <div id=\"contenttopcolumn\">                                 

                        </div>

                    </div>
<div id=\"container7\">
<div id=\"contentbottomcolumn\"> 

<h3> {$eventlist['title']} | {$eventlist['location']}</h3></a>
{$eventlist['date']} 
<p>
{$eventlist['date']}

 substr($eventlist['description'], 0, 40)





 </p>
 </div>
                        </div>




 ";

You have to close the string with something like ". ."

Like this:

 echo " <div id=\"container7\">
            <div id=\"contenttopcolumn\">                                 
            </div>
        </div>
        <div id=\"container7\">
            <div id=\"contentbottomcolumn\"> 
                <h3> {$eventlist['title']} | {$eventlist['location']}</h3></a>
                {$eventlist['date']} 
                <p>
                    {$eventlist['date']}
                        ".substr($eventlist['description'], 0, 40)."
                </p>
            </div>
        </div> 
 ";

Should also be noted that your HTML is invalid, closing </a> with no opening anchor tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM