user1592380
user1592380

Reputation: 36347

replace value in html with preg_replace

I have:

value="my_string"

in my HTML

I want to change this to:

value="my_second_string"

I've tried

~[value="]*?["]~'

This is not working. Could someone please advise me

Upvotes: 0

Views: 64

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 149068

In regular expressions, [] creates a character class, so your original pattern will match any number v, a, l, u, e, =, or " characters (non-greedily) followed by a single " character.

You can use this pattern to match value="my_string":

 ~value="[^"]*"~

This will match a literal value=" followed by any number of characters other than ", followed by a single " character.

Upvotes: 2

Related Questions