-1

i have a string

<div class="line"><input name="sid" value="" type="hidden"><img src="1.jpg" height="40" width="180"><input name="word" size="30" maxlength="50" value="" type="text"></div>

and i trying to find and replace whole input with name = word, with this regexp:

/<input .+?word.+?>/ui

preg_match returns this:

array (
  0 => '<input name="sid" value="" type="hidden"><img src="1.jpg" alt="CAPTCHA" height="40" width="180"><input name="word" size="30" maxlength="50" value="" type="text">',
)

please help me to write working regexp

2 Answers2

0

Use this one: /<input[^>]+name="word".+?>/ui

In your pattern it finds first <input and then until word... If you use <input[^>]+ it will find <input and than group of simbols except closing > until name="word".

Sergey Khalitov
  • 987
  • 7
  • 17
0

Use this one: /<input ([^>]+)?name=['"]?word['"]?([^>]+)?>/ui

AlVaz
  • 768
  • 1
  • 6
  • 21