-2

I think this has been done a million times but I can't get the expression right.

I need to str_replace an <input> element and everything between the So capture the id and the name enz...

So I thought:

<?php 
    $regex = '<input(.*?)>';
    $replacement = '<select>';
    $content = '<input id="id" name="name"/>text';
    $result = str_replace($regex, $replacement, $content);
    echo $result;
?>

I know this won't work but I think this should be the right way.

Anyone?

al'ein
  • 1,711
  • 1
  • 14
  • 21
Interactive
  • 1,474
  • 5
  • 25
  • 57

1 Answers1

3

Just use preg_replace:

<?php 
$regex = '#<input(.*?)>#';
$replacement = '<select>';
$content = '<input id="id" name="name"/>text';
$result = preg_replace($regex, $replacement, $content);
echo $result;
jmattheis
  • 10,494
  • 11
  • 46
  • 58