fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5.  
  6. $text = "edit:4961310112967 - edit:021331612649 Are these correct?";
  7. $format = '<a target="_blank" style="text-decoration: underline;color:purple;font-weight:bold;" href="../%s.php?UPC=%s">(View Product)</a>';
  8. echo "$text\n\n";
  9. $view = "/(view|edit)\:[0-9]+(\S)?/";
  10. if(preg_match_all($view, $text, $url, PREG_SET_ORDER)) {
  11.  
  12. foreach ($url as $val) {
  13. echo "(matched: " . $val[0] . ")\n";
  14. $checkCode = explode(":", $val[0]);
  15. $type = $checkCode[0] == 'view' ? 'index' : 'edit';
  16. $upc = $checkCode[1];
  17. $text = sprintf($format, $type, $upc);
  18. echo "$text\n";
  19. echo "({$checkCode[0]} - {$checkCode[1]})\n\n";
  20.  
  21. }
  22.  
  23. }
  24. echo "<br><br>".$text."<br><br>";
Success #stdin #stdout 0.01s 24144KB
stdin
Standard input is empty
stdout
edit:4961310112967 - edit:021331612649 Are these correct?

(matched: edit:4961310112967)
<a target="_blank" style="text-decoration: underline;color:purple;font-weight:bold;" href="../edit.php?UPC=4961310112967">(View Product)</a>
(edit - 4961310112967)

(matched: edit:021331612649)
<a target="_blank" style="text-decoration: underline;color:purple;font-weight:bold;" href="../edit.php?UPC=021331612649">(View Product)</a>
(edit - 021331612649)

<br><br><a target="_blank" style="text-decoration: underline;color:purple;font-weight:bold;" href="../edit.php?UPC=021331612649">(View Product)</a><br><br>