html - php - edit values from file -
i having problem editing value i've displayed file. i've gathered bits , pieces don't understand gives me desired functionality. appreciate help possible.
i have site displays values after match has been found:
search "s1value1" in sample.yml , display after ":" (this works fine)
search.php
$lines_array = file('sample.yml'); $search_string = "s1value1"; foreach($lines_array $line) { if(strpos($line, $search_string) !== false) { list(, $new_str) = explode(":", $line); $new_str = trim($new_str); } }
display.php
<form action="edit_value.php" method="post"> <td>s1value1:</td> <td>value:<input type="text" name="input1" value=<?php echo "$new_str"; ?>><input type="submit" name="submit" value="save"></td> </form>
but in display.php want able edit what's in input textbox , save file
(have no thought how that)
edit_value.php
have no thought here :(
here sample input file. i'm using .yml, cannot alter that.
sample.yml
service1: s1value1: 1 s1value2: 2 service2: s2value1: 1 s2value2: 2
thanks
assuming have @ moment ' one'
value. can utilize preg_replace quite simple pattern.
$str = ' one'; $str = preg_replace('/([ ]){1}([a-z]){3}/', ' two', $str);
on pattern ([ ]){1}([a-z]){3}
([ ]){1}
means preceeded 1 whitespace , ([a-z]){3}
3 lowercase letters in alphabet between or a
z
.
after comma ' two'
actual replacement. can want. , 3rd target replacing.
ps: im not in regex please right me if im wrong
php html
No comments:
Post a Comment