语法错误,线12上意想不到的'功能' [英] syntax error, unexpected 'function' on the line 12

查看:75
本文介绍了语法错误,线12上意想不到的'功能'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个url,其中包含各种POST数据和最后一个图像文件。我的示例链接是: http://website-link.com/?page=gf_signature&signature=565dbca63791e5.87676354.png



我想从网址中分离 565dbca63791e5.87676354.png ,并将其分隔(.png)。



我试过这个:

 <?php 
$ images = array() ;
$ imagesNew = array();
$ imgUrls =数组(
'ptSignature'=&';'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
'p签名'=>'http://website-link.com/?page=gf_signature&signature=5668694f80aa55.79055562.png',
'witness1Signature'=>'http://website-link.com/ ?page = gf_signature& signature = 5668695875c6e5.03917128.png',
'witness2Signature'=>'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',



函数make_without_ext($ str)
{
$ regex =/ signature =(?< signature> [^& )/;

preg_match($ regex,$ str,$ matches);
$ signature = $ matches [signature];
$ ext = substr(strrchr($ signature,'。',1);

$ without_extension = basename($ signature,'.png');
返回$ without_extension;
}


foreach($ imgUrls as $ imgUrl){
$ imgWithoutExt = make_without_ext($ imgUrl);
array_push($ images,$ imgWithoutExt);
}

foreach($ images as $ image){
$ content = file_get_contents($ image);
$ data = base64_encode($ content);
array_push($ imagesNew,$ data)
}

print'< pre>';
print_r($ imagesNew);
print'< pre>';

但它显示语法错误,意外的'function'(T_FUNCTION) code>

解决方案



  $ imgUrls = array(
'ptSignature'=>'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png' ,
'pSignature'=>'http://website-link.com/?page=gf_signature&signature=5668694f80aa55.79055562.png',
'witness1Signature'=>'http:/ /website-link.com/?page=gf_signature&signature=5668695875c6e5.03917128.png',
'witness2Signature'=>'http://website-link.com/?page=gf_signature&signature=5668695879dc84 .35037895.png',

使用分号可以解决问题。

I have an url which contains various POST-DATA in it And an image file at last. My example link is : http://website-link.com/?page=gf_signature&signature=565dbca63791e5.87676354.png

I want to seperate the 565dbca63791e5.87676354.png from the url and seperate the extension (.png) from it.

I have tried this:

<?php
    $images = array();
    $imagesNew = array();
    $imgUrls = array(
                    'ptSignature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
                    'pSignature' => 'http://website-link.com/?page=gf_signature&signature=5668694f80aa55.79055562.png',
                    'witness1Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695875c6e5.03917128.png',
                    'witness2Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
                )


    function make_without_ext($str)
        {
            $regex = "/signature=(?<signature>[^&]+)/";

            preg_match($regex, $str, $matches);
            $signature = $matches["signature"];
            $ext = substr(strrchr($signature, '.'), 1);

            $without_extension = basename($signature, '.png');
            return $without_extension;
        }


    foreach ($imgUrls as $imgUrl) {
        $imgWithoutExt = make_without_ext($imgUrl);
        array_push($images, $imgWithoutExt);
    }

    foreach ($images as $image) {
        $content = file_get_contents($image);
        $data = base64_encode($content);
        array_push($imagesNew, $data) 
    }

    print '<pre>';
    print_r ($imagesNew);
    print '<pre>';

But it shows syntax error, unexpected 'function' (T_FUNCTION)

解决方案

You have a missing semicolon after:

$imgUrls = array(
                    'ptSignature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
                    'pSignature' => 'http://website-link.com/?page=gf_signature&signature=5668694f80aa55.79055562.png',
                    'witness1Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695875c6e5.03917128.png',
                    'witness2Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
                )

Putting a semicolon would fix the problem in question.

这篇关于语法错误,线12上意想不到的'功能'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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