Reputation: 97
So I'd like a script that after sending a form it would add to numbers added in input form.
E.G.
Ability power ratio increased to <b>0.8</b> from <b>0.5</b>.
<b>20%</b> and <b>40/50/60/80</b>
I don't really know the logic behind script like that. I could possibly use substr() and check letter by letter first of all if it is a number or character. I'm sorry this question is so blunt but I have just no idea how to tackle this problem.
<form name="second_form" id="second_form" action="#" method="POST">
<div class="Change">
<textarea type="text" size="20" rows="3" cols="50" maxlength="500" name="SpellDescription[]" placeholder="Enter Description" required>
</textarea>
</div>
<br><br>
<input type="submit" name="submit">
</form>
Upvotes: 0
Views: 95
Reputation: 739
Try preg_replace
echo preg_replace( '/([0-9]+)\.?(\/?[0-9\.?]*)*%?/', '<strong>$0</strong>', 'test 0.1 this 5 test 0/1/2/3 5% 50% 5.5% 5 % . / 5/5.5/3/1.5/35.5/1.75');
You can try it out yourself here aswell: PHP Fiddle And to perfect the regex (as you can do so much with it), please fiddle arround on regexr
Edited the regex as suggested by caCtus, thanks for your input!
Upvotes: 2