I'm trying to build a list of array of mime types for PHP. I got a long list of mime types but I need to remove all the 'xxx' => upfront. How to detect them using regexp cos I tried '[\u][a-z0-9]' => and it didn't work.
'cpt' => 'application/mac-compactpro',
'cpt' => 'application/x-compactpro',
'cpt' => 'application/x-cpt',
'crl' => 'application/pkcs-crl',
'crl' => 'application/pkix-crl',
'crt' => 'application/pkix-cert',
'crt' => 'application/x-x509-ca-cert',
'crt' => 'application/x-x509-user-cert',
'csh' => 'application/x-csh',
'csh' => 'text/x-script.csh',
'css' => 'application/x-pointplus',
Try this ....
Find:^\s*'\w+' =>
Replace with:empty
You may try the following find and replace, in regex mode:
Find: ^\s*'.*?'\s*=>\s*('.*?',?)$
Replace: $1
Demo
Let's keep it simple. You need to search for ^\s*'\w\w\w' =>
Don't forget to set the Search Mode to Regular Expression in the search dialog.
Related
OK I am stumped.
I have tried numerous different approaches and I've spent the best part of a good few hours searching to no avail to my exact situation, that or I am tired and blind.
Here is the raw json pulled from a URI using file_get_contents():
{"id":"XXX","name":"Customer1","os":"CentOS Linux 7.3.1611 Core","cpu_type":"Intel(R) Xeon(R) CPU E3-1245 V2 # 3.40GHz","networking_v4":[{"addr":"xxx.xxx.xxx.xxx","if":"eth0"}],"networking_v6":[{"addr":"xxxx","if":"eth0"},{"addr":"xxxx","if":"eth0"}],"agent_version":0.96,"status":"up","last_update":1505949230,"first_update":1500588943,"notifications_count":8,"ip_whois":{"ip":"xxx.xxx.xxx.xxx","hostname":"xxx","city":"Garwood","region":"New Jersey","country":"US","loc":"xxx","org":"AS20473 Choopa, LLC","postal":"xxx"},"additional_fields":[{"value":"xxx","key":"Datacenter"},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""}]}
As you can see its a pretty simple request and I have every bit of data except those nested within networking_v4 and networking_v6.
I tried to access those like so:
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
Here is the full snapshot of code in its entirety:
$content = file_get_contents($url);
$json = json_decode($content);
$server_lastupd = $json->last_update;
$server_firstupd = $json->first_update;
$server = array(
'id' => $json->id,
'name' => $json->name,
'os' => $json->os,
'cputype' => $json->cpu_type,
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
'status' => $json->status,
'lastupd' => $json->$server_lastupd,
'firstupd' => $json->$server_firstupd,
'notifications' => $json->notifications_count,
'ip' => $json->ip_whois->ip,
'hostname' => $json->ip_whois->hostname,
'city' => $json->ip_whois->city,
'region' => $json->ip_whois->region,
'country' => $json->ip_whois->country,
'loc' => $json->ip_whois->loc,
'org' => $json->ip_whois->org,
'postal' => $json->ip_whois->postal,
'dctag' => $json->additonal_fields->dctag,
'source' => "XXX"
);
return $server;
So my issue is I appear to be unable to access the child content within networking_v4 and networking_v6.
Any help on this would be massively appreciated, its stumped me for the best part of 6 hours last night and a few more today, so I give in, someone please show me the light!
Many thanks :)
It looks like those are nested in arrays from the [{"key':"value"},{"key":"value"}] square brackets. have you tried
ipv4 => $json->networking_v4[0]->addr,
Try $json->networking_v4[0]->addr.
Both the networking_v4 and the networking_v6 keys point to arrays, so you need to pick which index you want to look at. The former only has one element, so it's easy to pick index 0, but the latter has multiple elements, so you'll need to figure out which one you want.
In roures.php file has contain
Route::get('roles/create',['as'=>'roles.create','uses'=>'RoleController#create','middleware' => ['permission:role-create']]);
Route::post('roles/create',['as'=>'roles.store','uses'=>'RoleController#store','middleware' => ['permission:role-create']]);
Route::get('roles/{id}',['as'=>'roles.show','uses'=>'RoleController#show']);
Route::get('roles/{id}/edit',['as'=>'roles.edit','uses'=>'RoleController#edit','middleware' => ['permission:role-edit']]);
Route::patch('roles/{id}',['as'=>'roles.update','uses'=>'RoleController#update','middleware' => ['permission:role-edit']]);
Route::delete('roles/{id}',['as'=>'roles.destroy','uses'=>'RoleController#destroy','middleware' => ['permission:role-delete']]);
Route::get('itemCRUD2',['as'=>'itemCRUD2.index','uses'=>'ItemCRUD2Controller#index','middleware' => ['permission:item-list|item-create|item-edit|item-delete']]);
Route::get('itemCRUD2/create',['as'=>'itemCRUD2.create','uses'=>'ItemCRUD2Controller#create','middleware' => ['permission:item-create']]);
Route::post('itemCRUD2/create',['as'=>'itemCRUD2.store','uses'=>'ItemCRUD2Controller#store','middleware' => ['permission:item-create']]);
Route::get('itemCRUD2/{id}',['as'=>'itemCRUD2.show','uses'=>'ItemCRUD2Controller#show']);
Route::get('itemCRUD2/{id}/edit',['as'=>'itemCRUD2.edit','uses'=>'ItemCRUD2Controller#edit','middleware' => ['permission:item-edit']]);
Route::patch('itemCRUD2/{id}',['as'=>'itemCRUD2.update','uses'=>'ItemCRUD2Controller#update','middleware' => ['permission:item-edit']]);
Route::delete('itemCRUD2/{id}',['as'=>'itemCRUD2.destroy','uses'=>'ItemCRUD2Controller#destroy','middleware' => ['permission:item-delete']]);
Expected output:
[
[
`url` => 'roles/create',
'as' => 'roles.create',
'uses'=>'RoleController#create'
],
[
`url` => 'roles/create',
'as' => 'roles.store',
'uses'=>'RoleController#store'
],
]
as so on
Here you can get the file content using file_get_content, we are using regex for parsing file content using regex.
Regex: /get\s*\(\s*'\K[^']+|as'\s*=>\s*'\K[^']+|uses'\s*=>\s*'\K[^']+/
get\s*\(\s*'\K[^']+ Here this will match Example: get(' match till '
as'\s*=>\s*'\K[^']+ Here this will match Example: as'=>' match till '
uses'\s*=>\s*'\K[^']+ Here this will match Example: uses'=>' match till '
Try this code snippet here
<?php
ini_set('display_errors', 1);
$string="Route::get('roles/create',['as'=>'roles.create','uses'=>'RoleController#create','middleware' => ['permission:role-create']]);
Route::post('roles/create',['as'=>'roles.store','uses'=>'RoleController#store','middleware' => ['permission:role-create']]);
Route::get('roles/{id}',['as'=>'roles.show','uses'=>'RoleController#show']);
Route::get('roles/{id}/edit',['as'=>'roles.edit','uses'=>'RoleController#edit','middleware' => ['permission:role-edit']]);
Route::patch('roles/{id}',['as'=>'roles.update','uses'=>'RoleController#update','middleware' => ['permission:role-edit']]);
Route::delete('roles/{id}',['as'=>'roles.destroy','uses'=>'RoleController#destroy','middleware' => ['permission:role-delete']]);
Route::get('itemCRUD2',['as'=>'itemCRUD2.index','uses'=>'ItemCRUD2Controller#index','middleware' => ['permission:item-list|item-create|item-edit|item-delete']]);
Route::get('itemCRUD2/create',['as'=>'itemCRUD2.create','uses'=>'ItemCRUD2Controller#create','middleware' => ['permission:item-create']]);
Route::post('itemCRUD2/create',['as'=>'itemCRUD2.store','uses'=>'ItemCRUD2Controller#store','middleware' => ['permission:item-create']]);
Route::get('itemCRUD2/{id}',['as'=>'itemCRUD2.show','uses'=>'ItemCRUD2Controller#show']);
Route::get('itemCRUD2/{id}/edit',['as'=>'itemCRUD2.edit','uses'=>'ItemCRUD2Controller#edit','middleware' => ['permission:item-edit']]);
Route::patch('itemCRUD2/{id}',['as'=>'itemCRUD2.update','uses'=>'ItemCRUD2Controller#update','middleware' => ['permission:item-edit']]);
Route::delete('itemCRUD2/{id}',['as'=>'itemCRUD2.destroy','uses'=>'ItemCRUD2Controller#destroy','middleware' => ['permission:item-delete']]);";
preg_match_all("/get\s*\(\s*'\K[^']+|as'\s*=>\s*'\K[^']+|uses'\s*=>\s*'\K[^']+/", $string,$matches);
$result=array();
for($x=0;$x<count($matches[0]);$x+=3)
{
$result[]=array(
'url'=>$matches[0][$x],
'as'=>$matches[0][$x+1],
'uses'=>$matches[0][$x+2]
);
}
print_r($result);
Use the following regex match and replace:
Match: .*\('([a-z\/{}0-9]+)',\['as'=>(['a-z\.0-9]+),'uses'=>(['a-zA-Z#]+).*
Replace: [url=> $1, 'as' => $2, 'uses' => $3]
PS. wherever you come by a space to match, use \s* to counter it
I am using Medoo but know very little php, the update below works fine but I only want it to update when the clientId matches what is posted:
$database->update("clientInfo", array(
"businessName" => $_POST['businessName'],
"contactName" => $_POST['contactName'],
"businessEmail" => $_POST['businessEmail'],
"businessPhone" => $_POST['businessPhone'],
"businessWebsite" => $_POST['businessWebsite'],
"businessAddress" => $_POST['businessAddress'],
"businessAddress2" => $_POST['businessAddress2'],
"businessCity" => $_POST['businessCity'],
"businessState" => $_POST['businessState'],
"businessZip" => $_POST['businessZip']
));
//$_POST["clientId"];
I am using a newer version of PHP and am a little confused on the syntax, here is how it is with older versions of PHP
http://medoo.in/api/update
I assume you have clientId field in that table, you can try:
$database->update("clientInfo", array(
"businessName" => $_POST['businessName'],
"contactName" => $_POST['contactName'],
"businessEmail" => $_POST['businessEmail'],
"businessPhone" => $_POST['businessPhone'],
"businessWebsite" => $_POST['businessWebsite'],
"businessAddress" => $_POST['businessAddress'],
"businessAddress2" => $_POST['businessAddress2'],
"businessCity" => $_POST['businessCity'],
"businessState" => $_POST['businessState'],
"businessZip" => $_POST['businessZip']
), array(
"clientId" => $_POST['clientId']
));
Hope it helps.
How can I get all meanings of a word using Google Translate API v2?
I get a response with only one thing like translatedText => "text", but I need to get all meanings of the word.
These are my parameters:
'key' => $this->_apiKey,
'target' => $target,
'q' => $data,
'multires' => 1,
'otf' => 1,
'client' => 't',
'multires' => 1,
'pc' => 0,
'sc' => 1
As we can read on Translate API FAQ
Is it possible to get multiple translations of a word? No. This
feature is only available via the web interface at
translate.google.com
I'm having some trouble with redirection in config/routes.php file
I can't find the right regex
$_skill = '[A-Za-z\-]+'
Router::connect('/-:skill/:city-:zipcode:shit', array('controller' => 'redirects', 'action' => 'district'),
array('city' => '[A-Za-z-0-9\]+.(er|eme)-arrondissement',
'skill' => $_skill,
'zipcode' => $_zipcode,
'shit' => '(.*)',
'pass' => array('zipcode'),
)
);
I would like to match any url where city ends with 'arrondissement' but i'm a total noob in regex
thank you.
With most regex you can use the dollar symbol to match the end of a string.
simply 'arrondissement$'
And drop all the stuff at the beginning.