PHP:如何仅从变量中获取文本?
如何仅从表中获取文本数据?没有任何链接和图片PHP:如何仅从变量中获取文本?,php,gettext,Php,Gettext,如何仅从表中获取文本数据?没有任何链接和图片 while ($row = $most_rep->fetch_assoc()) { $post_title = $row['post_title']; $post_content = mb_substr($row['post_content'],0,120); $guid = $row['guid']; $post_date = $row['post_date']; echo "<
while ($row = $most_rep->fetch_assoc()) {
$post_title = $row['post_title'];
$post_content = mb_substr($row['post_content'],0,120);
$guid = $row['guid'];
$post_date = $row['post_date'];
echo
"<a href='$guid' target='_blank'>"
."<div class='post_title'>$post_title</div>"."</a>"
."<a href='$guid' target='_blank'>"
."<div class='post_description'>$post_content</div>"
."<div class='post_date'>$post_date</div>"
."</a>";
}
在变量$post_内容中,我有文章中的文本、图像和链接。我只想回显文本
感谢您的帮助这不是最佳做法,但如果您仍然坚持使用这种方法,我建议您在数据$row['post\u content']中添加一些分隔符,并使用explode,$row['post\u content']来获取所需的特定文本或值
注意:explode函数将返回一个数组。使用'strip\u tags'函数 比如说,
$only_text=strip_tags$post_content 您可以使用PHP过滤器清理:
<?php
$str = "test";
$newstr = filter_var($str, FILTER_SANITIZE_STRING);
echo $newstr;
?>
尝试此操作以删除除a-z、a-z和0-9之外的所有内容: $result=preg_replace/[^a-zA-Z0-9]+/,$s; 如果字母数字的定义包括外语字母和过时的脚本,则需要使用Unicode字符类 尝试此操作以仅保留A-Z: $result=preg_replace/[^A-Z]+/,$s;
发出警告的原因是,像résumé这样的词包含了与此不匹配的字母。如果要匹配特定的字母列表,请调整正则表达式以包含这些字母。如果要匹配所有字母,请使用注释中提到的适当字符类。美元行['post_content']中有什么?带strip_标记?只需选择包含文本的字段,而不是包含链接和图像的字段?