Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php解析httpapi响应_Php - Fatal编程技术网

用php解析httpapi响应

用php解析httpapi响应,php,Php,我正在使用域分销商API,它以html格式提供响应。 但是,它根本没有格式化。我得到这样的东西,以一个字符串的形式: domain.com: error: 102 your credentals are wrong 或 我只对状态代码感兴趣,通过它我可以向客户发送自定义消息。我如何从这个字符串解析代码? 请注意,响应的长度可能会有所不同。我正在考虑使用reg exp 谢谢此代码可能有效 $string='other-domain.net: OK: 202 domain is availabl

我正在使用域分销商API,它以html格式提供响应。 但是,它根本没有格式化。我得到这样的东西,以一个字符串的形式:

domain.com: error: 102 your credentals are wrong 

我只对状态代码感兴趣,通过它我可以向客户发送自定义消息。我如何从这个字符串解析代码? 请注意,响应的长度可能会有所不同。我正在考虑使用reg exp

谢谢

此代码可能有效

$string='other-domain.net: OK: 202 domain is available';
$array = explode(' ', $string);
echo $array[2]; // 202

显然,状态码的前缀总是冒号和空格

$statusText = 'other-domain.net: OK: 202 domain is available';

$status = preg_replace( '/.*: (\d+).+/', '$1', $statusText );

我尝试过使用reg exp和本机PHP字符串操作的版本。我担心响应长度的变化。我明白了,但您的代码在哪里?;-)这就是我第一个问题的全部意图…
$statusText = 'other-domain.net: OK: 202 domain is available';

$status = preg_replace( '/.*: (\d+).+/', '$1', $statusText );