douwei3280
douwei3280
2018-09-17 11:54
采纳率: 0%
浏览 26
已采纳

如何在php 5.4.0中修复位置时如何从给定字符串中获取字符串的一部分[复制]

This question already has an answer here:

I have a code which fetches only TANID from the Cookies. Position of TANID is not fixed. This code is working fine on php 7.2 but not on php 5.4

<pre><?php
$myfile = fopen("auth-20180925.log", "r");
$content= fgets($myfile);
$carray=explode('-,-',$content);
$mt = $carray[6];
$data=array_column( array_map(function($v) { return explode('=',trim($v));},explode(';',substr($mt,strpos($mt,'=')+1))),1,0);
$SESSION_COOKIES= ($data['TANID']);
echo $SESSION_COOKIES;
?>

However this code is not running on php 5.4.0 I checked and found array_column is not supported by php 5.4.0. Can someone please suggest how can i achieve this in php 5.4.0

My "auth-20180925.log" looks like this:

2018/09/25 08:32:54-,-dev3.office.abc.eu.com-,-10.00.97.000-,-createAuthenticatedSession-,-00255866-,-"yoya session Created.-,-DST=R4;TANID=31d5865cd24c6c3348gjhdfjghfa79bca
2018/09/17 08:35:09-,-dev3.office.abc.eu.com-,-10.61.88.222-,-logout-,-001586284-,-"yoya session Logout.-,- (TANAUTH=6424f5a9e1b84802abe4b66abc7d8536; MultisecureUserId=00198345; authMarket=be; website=OFFICE; DST=R4; authscheme=SOFTTOKEN; TANID=81110436dfghjdfgj6a402b74; PHPSESSID=fgsfsdf5546545df; market=be)"

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdf64562672
    dsdf64562672 2018-09-17 12:14
    已采纳

    For your case, a simple foreach will suffice:

    $data = array_map(function($v) { return explode('=',trim($v));},explode(';',substr($mt,strpos($mt,'=')+1)));
    foreach ($data as $datum) {
        if ($datum[0] == 'TANID') {
            $SESSION_COOKIES= $datum[1];
            break;
        }
    }
    echo $SESSION_COOKIES; 
    
    点赞 评论

相关推荐