简体   繁体   English

在php中将字符串转换为数字

[英]Convert a string to number in php

I have this line of code... 我有这行代码......

$ide=str_replace('idEdu=', '', $_SERVER['QUERY_STRING']);

In which i get a string which is always a number and I want this string to make it integer. 其中我得到一个始终是数字的字符串,我希望这个字符串使其成为整数。

I want to get for example the number 3 for the url which can be like this one addCV.php?idEdu=3 我想得到例如url的数字3,它可以像这样一个addCV.php?idEdu = 3

Can you help me please to achieve that? 你可以帮助我实现这个目标吗? Thank you 谢谢

You can either cast as int or use intval(): 您可以转换为int或使用intval():

 $num=(int)$_GET['idEdu'];

or 要么

 $num=intval($_GET['idEdu']);

Casting should be 4 times as fast. 铸造应该快4倍。

你有没有尝试过?

$ide = intval(str_replace('idEdu=', '', $_SERVER['QUERY_STRING']));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM