fork download
  1. <?php
  2.  
  3. $string =
  4. '<ul>
  5. <li>
  6. <a href="/nalcrom">Nalcrom</a>
  7. (Sodium Cromoglicate)
  8. </li>
  9. <li>
  10. <a href="/alimemazine">Alimemazine</a>
  11. </li>
  12. <li>
  13. <a href="/xolair">Xolair</a>
  14. (Omalizumab)
  15. </li>
  16. </ul>';
  17.  
  18. preg_match_all('%">(.*?)</a>\s+(\(.*?\))?%i', $string, $match, PREG_PATTERN_ORDER);
  19. for ($i = 0; $i < count($match[0]); $i++) {
  20. echo $match[1][$i] . " ". $match[2][$i] ."\n";
  21. }
Success #stdin #stdout 0.02s 24144KB
stdin
Standard input is empty
stdout
Nalcrom (Sodium Cromoglicate)
Alimemazine 
Xolair (Omalizumab)