Cell xfields contains several references in this way. audio|vip.mp3||image|vip.jpg||wave|19.jpg

If I output this way ".$row['xfields']." the entire cell is displayed.

How to display only the image vip.jpg

Full code

 $sql = $db->query("SELECT * FROM ".PREFIX."_post ORDER BY id DESC"); while ($row = $db->get_row($sql)) { $row['date'] = strtotime($row['date']); if ($config['allow_alt_url'] == "yes") $rat .= "<div class=\"rate\"><a {$go_page}href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">".$row['tags']." - ".$row['title']."</a></div>"; else $rat .= "<div class=\"rate\"><a {$go_page}href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">".$row['tags']." - ".$row['title']."</a></div>"; 

After $rat .= " Need to output

  • echo explode('|', $row['xfields'])[4]; ....... but it is better not to keep it that way, IMHO - Alexey Shimansky
  • Gives an error message. Paste need after $rat .= " - steep

1 answer 1

Like that

 //метод один $str = 'audio|vip.mp3||image|vip.jpg||wave|19.jpg'; preg_match('#image\|([^|]+\.(?:gif|jpe?g))\|#isU', $str, $matches); if (isset($matches[1])) { echo $matches[1]; } //метод два $str = 'audio|vip.mp3||image|vip.jpg||wave|19.jpg'; $list = explode('||', $str); foreach ($list as $val) { $arr[explode('|', $val)[0]] = explode('|', $val)[1]; } if (isset($arr['image'])) { echo $arr['image']; } 
  • And how to use it? I do not need one picture to display. They have different names. - steep
  • @steep well, so more information should be thrown into the question. - Jean-Claude