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


Retrieve records and convert them into new with string functions

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

我有一个名为"食谱"的数据库,表名为"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. 连接数据库,从内容字段中检索数据table posts

  2. 查找所有数字,并在其中的前面加上li标签,直到

  3. 查找单词"Instructions"后的所有li标签并删除它们。(这是因为许多食谱在"说明"后面有li标签,必须删除)

  4. 查找所有li标签并添加class="ingredient"

  5. 添加一些"class text"在

  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浏览器中使用正确的编码设置解决了希腊字符问题到目前为止一切顺利。现在我需要代码来替换字符,直到满足单词"说明"什么好主意吗?

第一步

选择一个适合你的风格和需要的开发框架。

步骤2

阅读相关的文档,并跟随一些简单的例子。

步骤3

应用程序!

与使用框架相比,从第一原则来做这些是极其困难和耗时的。

'r'n(你有/r/n,这是完全不同的,大概是一个打字错误)到<br>的机械翻译是大多数框架都有方法的。

除此之外的任何内容都是自定义代码,但除了列出规范之外,您实际上没有做任何事情。不要把Stack Overflow和你雇佣程序员的地方混淆了。

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