gpt4 book ai didi

php - 检索记录并使用字符串函数将其转换为新记录

转载 作者:行者123 更新时间:2023-11-30 00:33:10 28 4
gpt4 key购买 nike

这对我来说太复杂了,所以我需要你的帮助

我有一个名为“recipes”的数据库,其表名为“posts”,其中有一个字段“content”,并包含以下形式的食谱:

Ingredients\r\n
1 tomato\r\n\
2 eggs\r\n
500 gr olive oil\r\n
etc...

Instructions\r\n
Do this do that\r\n
etc...

我需要将此记录转换为:

<div class="Ingredients">
<div class="name"> must be string from field "post_name" from table "posts"
<li class="ingredient">1 tomato</li>
<li class="ingredient">2 eggs</li>
<li class="ingredient">500 gr olive oil</li>
</ul>
<div class-"Instructions"</div>
<ol>

<div class="instruction">Do this do that etc...
</div>

所以我需要以下东西:

  1. 连接数据库并从内容字段检索数据表格帖子

  2. 搜索所有数字并在它们之前添加 li 标记,直到符合“成分”一词。

  3. 查找“Instructions”一词后面的所有 li 标签并将其删除。 (发生这种情况是因为许多食谱在“说明”一词后面都有 li 标签,必须将其删除)

  4. 找到所有 li 标签并向其添加 class="ingredient"。

  5. 在末尾添加一些“类文本”最后一个结束 li 标记。

  6. 替换字段内容中的所有旧记录与新的

如有任何帮助,我们将不胜感激

编辑:到目前为止我所做的是与数据库的连接

<?php
mysql_connect("localhost","root","") or die (mysql_error());
echo "Connected to MySQL<br /><hr />";
mysql_select_db("word") or die (mysql_error());
mysql_query("SET character_set_results = 'utf8'");
echo "Connected to Database<br /><hr />";
$query = "SELECT * FROM wp_posts";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row['ID'] . " - " . $row['post_title'];
echo "<br /n>";
}
?>

EDIT2:希腊字符的问题通过 Chrome 浏览器中的正确编码设置解决到目前为止,一切都很好。现在我需要代码来替换字符,直到遇到“指令”一词有什么想法吗?

最佳答案

第 1 步

选择一个development framework适合您的风格和需求。

第 2 步

阅读与之相关的文档并遵循一些简单的示例。

第3步

申请!

与使用框架相比,从基本原理开始执行此操作极其困难且耗时。

来自 \r\n 的机械翻译(你有 /r/n 这是完全不同的,可能是一个拼写错误)到 <br>大多数框架都有方法。

除此之外的任何内容都是自定义代码,但除了列出规范之外,您还没有真正做过任何事情。不要将 Stack Overflow 与雇用程序员的地方混淆。

如果您了解 PHP 的字符串和数组操作技术,那么您在这里描述的内容是相当简单的,所有这些都在 the documentation 中进行了描述。 .

关于php - 检索记录并使用字符串函数将其转换为新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22365844/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com