How to specify numbers between characters in percentage 64.90 Hi!
53.64 Hi!
80.90 He Hao
53.64 Haha
40.90 Haha
53.64 Oh
For example, $ num is used to obtain the content of the above page.
How The number between two decimal places is equal to 80% of the original number.
The number between two decimal places is equal to 60% of the original number.
Retain other content on the original page, including text
Reply to discussion (solution)
$ S = <TXT
64.90
Hi!
53.64
Hi!
80.90
He Hao
53.64
Haha
40.90
Haha
53.64
TXT; echo preg_replace_callback ('/(
|
) ([\ D.] +)/', function ($ m) {return sprintf (' % s %. 2f ', $ m [1], $ m [2] * ($ m [1] ='
'? 0.8: 0.6) ;}, $ s );
51.92
Hi!
32.18
Hi!
64.72
He Hao
32.18
Haha
32.72
Haha
32.18
Oh
The code you gave me is incorrect.
Parse error: syntax error, unexpected T_FUNCTION in C: \ 111.php on line 10
Can I get the value equal to the variable? how can I write it?
$ P = preg_replace_callback ('/( | ) ([\ D.] +)/', function ($ m) {return sprintf (' % s %. 2f ', $ m [1], $ m [2] * ($ m [1] =' '? 0.8: 0.6) ;}, $ s );
Your php version earlier than 5.3 does not support anonymous functions.
function foo($m){ return sprintf('%s%.2f', $m[1], $m[2] * ($m[1] == '
' ? 0.8 : 0.6));}$p = preg_replace_callback('/(
|
)([\d.]+)/', "foo", $s); echo $p;