PHP:文本处理 preg_match 函数 [英] PHP: Text Processing preg_match function

查看:83
本文介绍了PHP:文本处理 preg_match 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
$eqn1="0.068683000000003x1+2.046124y1+-0.4153z1=0.486977512";
preg_match("/\b[0-9]*\b/",$eqn1,$vx1);
echo "X1 is: $vx1[0]";
?>

谁能告诉我,如何将 x1 的值(即 0.068683000000003)存储在变量 $vx1 中?

Can someone tell me, how to store the value of x1 (that is, 0.068683000000003) in the variable $vx1?

输出为:

X1 is: 0

推荐答案

你的正则表达式只考虑整数,你的第一个数字是小数.

Your regex takes into account only integer, your first numùber is a decimal one.

这是一种完成工作的方法,您要查找的号码在第 1 组中:

Here is a way to do the job, the number you're looking for is in group 1:

$eqn1 = "0.068683000000003x1 + 2.046124y1 + -0.4153z1 = 0.486977512";
preg_match("/^(\d+\.\d+)/", $eqn1, $vx1);
echo "X1 is: ", $vx1[1], "\n";

输出:

0.068683000000003

这篇关于PHP:文本处理 preg_match 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆