How to specify numbers between characters in percentage

Source: Internet
Author: User
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;
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.