我有这张表plans
id| plan_name| description
1 | basic | Good plan for startups <br>
Excellent quality <br>
Lorem ipsum Lorem
我想echo
只使用PHP中的查询description
列中的前两行。
查询
$getuserplaninfo=mysqli_query($db, "SELECT * FROM plans WHERE membershipID='$userplanID'");
$userplaninforesults=mysqli_fetch_assoc($getuserplaninfo);
$userplaninfo=$userplaninforesults['description'];
echo $userplaninfo;
结果应为
Good plan for startups
Excellent quality
答案 0 :(得分:3)
使用explode
$userplaninfo = "Good plan for startups <br>
Excellent quality <br>
Lorem ipsum Lorem";
$userplaininfo_array = explode("<br>",$userplaninfo);
$userplaininfo = $userplaininfo_array[0];
if(isset($userplaininfo_array[1]))
{
$userplaininfo .= "<br>".$userplaininfo_array[1];
}
echo $userplaininfo;
答案 1 :(得分:0)
您可以使用PHP substr
函数获取子字符串。
$userplaninfo = substr($userplaninforesults['description'], 45);