[英]Extracting from array using PHP
I am learning PHP and I'm trying to understand the array below, I need to grab content-type , it should give me 我正在学习PHP并且试图理解下面的数组,我需要获取content-type ,它应该给我
Anyone good with arrays could you please help? 擅长数组的人可以帮忙吗?
array(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 30 Aug 2014 17:10:12 GMT
[2] => Server: Apache
[3] => X-Gas_TTL: 900
[4] => Cache-Control: max-age=900
[5] => X-GasHost: gas1.usw
[6] => X-Cooking-With: Gasoline-Local
[7] => X-Gasoline-Age: 844
[8] => Last-Modified: Sat, 30 Aug 2014 16:56:08 GMT
[9] => Content-Type: text/xml;charset=UTF-8
[10] => Vary: Accept-Encoding
)
Thank you in advance 先感谢您
Regards, Mona 蒙娜娜
.*?Content-Type:\s*(.*?=(.*?))\n.*
With s flag on this will give what's required. 带有s标志将提供所需的内容。
See demo. 参见演示。
http://regex101.com/r/bJ6rZ5/1 http://regex101.com/r/bJ6rZ5/1
The array must be in a variable ( I assume, since you seem to have printed it ), so you simply print/echo the value you're after. 数组必须在变量中(我认为,因为您似乎已经打印了它),因此您只需打印/回显您要的值即可。
echo $someArrayVariable[9];
Where someArrayVariable is a variable that contains the array. 其中someArrayVariable是包含数组的变量。
That is assuming it is in a variable in the first place. 假设它首先位于变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.