PHP square brackets syntax [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Given this code snippet:
$nodes[$record->nid]->group = $record->group;
I do not understand what the first part (to the left of the equals sign) means?
Thanks.

$nodes is an array, and $record->nid is an index in that array. For this code to be valid, $record->nid must be either a string or an integer.
Calling $nodes[$record->nid] will return an object, that you are then calling group on.

I do not understand what the first part (to the left of the equals sign) means?
Breaking $nodes[$record->nid]->group apart:
$nodes is an array of objects
$nodes[$record->nid] accesses the element with a key of $record->nid
$nodes[$record->nid]->group access the group property of the object ($nodes[$record->nid])

Related

Remove characters from a string till another character comes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I remove characters till there comes another character in a string?
For example:
String is this: 0030051
Now I want to remove ALL 0's before another character (like: 1) comes.
So the string will become this: 30051.
Is there a PHP function for this or is this easier with Javascript/jQuery ? (I'd prefer PHP)
cast it to integer
$var = (int)$var;
Source - Reference

php Regular Expression match custom [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm not very good at regular expressions. Please help make the expression.
$subject = "action[attribute1=value1,attribute2=values,...]";
// format is ^word[str=str,...]$
I need to match "action", "attributes" and "values". thanks.
First find a match with regex pattern \b(\w+)\[((?:(?<=[,\[])(?:\w+)=(?:[^,\]]+)[,\]]?)+)]
to get action name as Group 1 and parameter list as Group 2.
In next step apply regex pattern (?:^|(?<=,))(\w+)=([^,\]]+)(?=,|$) to Group 2 from above regex
to get a list of attributes and associated values...

Retrieve mysql data that doesn't contain number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to retrieve a list of words, but don't want any words that contain a number or numbers in them.
The idea is very simple, but I'm not even sure how to try. I have one column of words some of which have numbers in them. I only want to retrieve the ones without numbers.
How would I do this in my SQL query?
Thanks
Use a regular expression, either with php's preg_match, or with REGEXP in mysql.
SELECT list_col FROM list_table WHERE list_col NOT REGEXP '[0-9]'

How can I parse this JSON? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I can't get the "img_url" (on third line) value from the JSON using PHP. Here's the JSON string:
Edit (This is the JSON, my apologies for posting the var_dump):
{"status_code":200,"status_txt":"OK",
"data":{"img_name":"KdxIC.png","img_url":"http:\/\/s0.uploads.im\/KdxIC.png",
"img_view":"http:\/\/uploads.im\/KdxIC.png","img_width":"504","img_height":"504",
"img_attr":"width=\"504\" height=\"504\"","img_size":"15.1 KB","img_bytes":15494,
"thumb_url":"http:\/\/s0.uploads.im\/t\/KdxIC.png","thumb_width":360,"thumb_height":360,
"source":"http:\/\/site.com\/uploads\/icon1#2x.png","resized":"0","delete_key":"6e814d3c5201feee"}}
The accepted answer works. Thanks
That code is not json, its a php dump of an array.
If you want to access the image url do this:
I'm using this example url.
$imgdata = json_decode($response, true);
echo $imgdata["data"]["img_url"];
Output:
http://s0.uploads.im/go0WK.png
Edit:
Do not use the second param in json_decode, that is converting your object to an array.

php filter with get variables [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I suck at regexp but i'd like to just do a simple filter where / is replaced with 1, " is replaced with 2 and < is replaced with 3.
I'd appreciate an example where the syntax would be straight forward, i'd like to run this filter through the input of a get variable provided by the user. A syntax like:
replace(/,1)
replace(",2)
replace(<,3)
.
Thanks.
I really don't see the need for regex here.. You can just use str_replace
E.g.
str_replace('/', '1', $_GET['var']);

Categories