提前感谢您抽出宝贵时间解决我的问题。
我正在使用 PHP 脚本来查询 mySQL 数据库。不幸的是,产品描述、成分和附加信息(最后的段落)都与名称一起存储在一个字段中(名称是多余的,可以忽略)。所有文本都包含在 HTML 代码中。我不想保留或存储任何 HTML 代码,但它可能用作分隔符。
重要提示: HTML 是编码存储的,所以
<p>
存储为
<p>
下面是一个存储在 mySQL 数据库中的 HTML 代码示例(这正是它的存储方式。正如我之前提到的,HTML 是经过编码的。):
<table border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr valign="top">
<td>
Item:</td>
<td>
Olive Loaf - Baked - <b>Gluten Free!</b></td>
</tr>
<tr valign="top">
<td>
Description:</td>
<td>
A blend of beef and pork along with our unique spices to create a base mix. To this mix we add plenty of olives and form it into a loaf, we then smoke this over natural hardwoods for a unique Koegel flavor.</td>
</tr>
<tr valign="top">
<td>
Ingredients:</td>
<td>
Beef and Pork, Water, Spanish Olives (Olives, Pimentos, Sodium Alginate, Guar Gum, Calcium Chloride, Water, Salt, Lactic Acid), Nonfat Dry Milk, Corn Syrup, Salt, Red Sweet Peppers (bell peppers, water, citric acid.), Spices, Dextrose, Dehydrated Onions.</td>
</tr>
</tbody>
</table>
<p>
<strong>Each loaf weighs approximately 6 lbs.</strong></p>
这是与 HTML 解码相同的代码片段(这不是它在 mySQL 数据库中的存储方式。我提供这个只是为了视觉。):
<table border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr valign="top">
<td>
Item:</td>
<td>
Olive Loaf - Baked - <b>Gluten Free!</b></td>
</tr>
<tr valign="top">
<td>
Description:</td>
<td>
A blend of beef and pork along with our unique spices to create a base mix. To this mix we add plenty of olives and form it into a loaf, we then smoke this over natural hardwoods for a unique Koegel flavor.</td>
</tr>
<tr valign="top">
<td>
Ingredients:</td>
<td>
Beef and Pork, Water, Spanish Olives (Olives, Pimentos, Sodium Alginate, Guar Gum, Calcium Chloride, Water, Salt, Lactic Acid), Nonfat Dry Milk, Corn Syrup, Salt, Red Sweet Peppers (bell peppers, water, citric acid.), Spices, Dextrose, Dehydrated Onions.</td>
</tr>
</tbody>
</table>
<p>
<strong>Each loaf weighs approximately 6 lbs.</strong></p>
基本上,我想忽略名称,将描述和附加信息(描述下方的最后一段)保存为$productDescription(可能在描述后添加两个换行符以分隔附加信息),并将成分保存为$productIngredients。我不想包含文本“描述:”或“成分:”......只是紧随其后的信息。如上所述,我只对原始文本感兴趣——我不想保存任何 HTML 代码。将信息存储到 2 个变量中时,应忽略所有 HTML 代码。
任何帮助都将不胜感激!
谢谢,
-杰夫
编辑
发生的事情是 mySQL 数据库连接到一个 opencart 网站。在网站的管理方面,没有单独的成分、描述等字段。还有其他所有内容(重量、尺寸、SKU、型号等)。这是因为 opencart 网站并非专门用于食品。它可以用于电子产品,在这种情况下,不需要这些领域。店主(不是我)将所有这些信息输入到描述入口点。HTML 可能会泄露这一点。该网站由另一个人管理(如果需要,我可以直接与他联系)。我不希望他或我自己更改 opencart 代码以添加额外的字段,除非它可以轻松完成。
向 opencart 网站添加其他字段是否容易?这样,描述字段可以是独占的。感谢您的回复。