down2323 2014-04-16 20:55
浏览 76
已采纳

PHP / MySQL帮助在分隔符和ID之间解析/提取

I've imported data from SharePoint into a MySQL database and I need to extract and format some data out of a string while ignoring the numerical SharePoint IDs in between the delimiters. Example Name field with multiple entries as a string :

Smith, Bob;#5800;#Jones, Mark;#6067;#Brown, Alex

I want the output to look like this:

Smith, Bob</br>
Jones, Mark</br>
Brown, Alex

My current query works and returns the results. Current query:

<?php 
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)) {
?>
<tr>
  <td><?php echo $row["Project Title"]; ?></td>
  <td><?php echo $row["Project Description"]; ?></td>
  <td><?php echo $row["Project Sponsor(s)"]; ?></td>
</tr>
<?php } ?>

The field containing this particular string is Project Sponsor(s).

How do I parse with these random IDs with the #; delimiter?

Help?

  • 写回答

3条回答 默认 最新

  • dongling5411 2014-04-16 21:05
    关注

    Just replace with <br />:

    echo preg_replace('/;#?[^;]+;#?/', '<br />', $row['Project Sponsor(s)']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗