Ok, so say I have a bunch of inputs in an HTML file like this:
<input class="form-control" type="text" id="ogwb">
<input class="form-control" type="text" id="aosgh">
<input class="form-control" type="text" id="aghw">
How can I replace all instances of the ids with themselves and a name and value attribute having the same id value like so:
<input class="form-control" type="text" id="ogwb" name="ogwb" value="<?php echo htmlspecialchars($_POST['ogwb']); ?>">
<input class="form-control" type="text" id="aosgh" name="aosgh" value="<?php echo htmlspecialchars($_POST['aosgh']); ?>">
<input class="form-control" type="text" id="aghw" name="aghw" value="<?php echo htmlspecialchars($_POST['aghw']); ?>">
This is what I've tried:
f = File.read('my.html')
$arr = f.scan(/id="([^"]*)"/)
$arr.each{ |a|
e_ = a.join(", ")+'"'
e__ = a.join(", ")+'"'+' name="'+a.join(", ")+'" value="<?php echo htmlspecialchars($_POST['+"'"+a.join(", ")+"'"+']); ?>"'
f.gsub(/#{e_}/,e__)
}
Which if I do puts e_ and puts e__ I get the match and replace I want, but gsub doesn't seem to work.