Skip to content

Use PHP to output a string according to JavaScript object format

License

Notifications You must be signed in to change notification settings

CaryGuo/PHP-Output-JavaScript-Object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

PHP-Output-JavaScript-Object

Use PHP to output a string according to JavaScript object format

PHP输出JavaScript对象格式的字符串

Exp:

<?php
$array = ['string'=>'jefja','array'=>['a',2],'num'=>123];

echo jsobj_encode($array);

function jsobj_encode($array)
{
    $json = json_encode($array);
    $pattern = "/\"([^,\"]*?)\":.*?/";
    $result =  preg_replace_callback($pattern, function($matches){
	    return $matches[1].":";
    }, $json);
    return $result;

   }

It will be output a string, like this:

以上代码输出:

{string:"jefja",array:["a",2],num:123}

About

Use PHP to output a string according to JavaScript object format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages