right code with json_decode function [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
I have an error while i try to activate a wp plugin:
Parse error: syntax error, unexpected '[' at this line :
$site_name = json_decode(curl_exec($ch), true)["site_name"];
This can be fixed by setting PHP to >= 5.4 OR with the post below.

You can only use that syntax in PHP >= 5.4. Otherwise, you need to save the result from json_decode into its own variable and then use that to get the site_name.
$JSONdata = json_decode(curl_exec($ch), true);
$site_name = $JSONdata["site_name"];

You need PHP 5.4 for this to work. If you are running older PHP version (and assuming this plugin does not need PHP5.4 for other things) then replace this code with:
$tmp = json_decode(curl_exec($ch), true);
$site_name = $tmp["site_name"];

Related

convert short youtube url to full url [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
Hi all i am looking for a simple way to check if a string equals an url like this:
http://youtu.be/WWQZ046NeUA
To convert it to a proper youtube url like this:
http://www.youtube.com/watch?v=WWQZ046NeUA
If not to leave it alone, what's the simplest way to do it in php?
You can use this preg_replace call:
$u = 'http://youtu.be/WWQZ046NeUA';
$r = preg_replace('~^https?://youtu\.be/([a-z\d]+)$~i', 'http://www.youtube.com/watch?v=$1', $u);
str_replace should work wonders.
$url = ''; //url you're checking
$ytshorturl = 'youtu.be/';
$ytlongurl = 'www.youtube.com/watch?v=';
if (strpos($url,$yturl) !== false) {
$url = str_replace($ytshorturl, $ytlongurl, $url);
}

A php Error in site [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
Parse error: syntax error, unexpected T_IS_IDENTICAL in /home/vvcoutur/public_html/wp-content/themes/stoconverge/header.php on line 54
This is line 54:
<?php ======= COOKIE DEMO OPTIONS ======= //wp_enqueue_style('skins', get_template_directory_uri(). '/admin/layouts/' . $data['alt_stylesheet'] ); ?>
What am i getting wrong
======= COOKIE DEMO OPTIONS =======
should be a comment it isn't and your code is commented out. Try this :
<?php /**======= COOKIE DEMO OPTIONS =======**/ wp_enqueue_style('skins', get_template_directory_uri(). '/admin/layouts/' . $data['alt_stylesheet'] ); ?>
With better formatting and using an IDE you would have seen this easily.

Syntax error - PHP [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
Hi Dreamweaver says there is a syntax error on the following line. Is it right?
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
Indexing the return value of a function is not supported in the version of PHP in use. Upgrade to a newer version, or turn it into separate statements.
It is probably not parsing for php 5.4 which is what is required to understand the function()[0] syntax.
Also your parameted for in_array() are incorrect
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Dreamweaver is the CULPRIT !
Your code is just fine. I tried your code and it works fine.
Since you haven't disclosed us the variables. $file and $allowedExtensions. I assume this is what you must be doing.
Also, the if loop is just fine.
Get a new editor like PHPStorm or Eclipse for PHP
<?php
$file=array('name'=>'test.gif');
$allowedExtensions=array('.gif','.jpg','.png');
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
{
echo "Valid File Extension";
}
else
{
echo "Invalid File Extension";
}

Parsing XML from a Web Page with PHP [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 heard that you can parse information from a web page with SimpleXML.
How can I get the the Usernames and ID's from the following page and display them on my website like:
Username:Napolien
Id:2202591
The URL to the website from which I want to get the information is:
http://api.roblox.com/users/3/friends
Your api returns json, you can decode it with json_decode, i have also include how to traverse through the json objects included in the feed.
$json = file_get_contents("http://api.roblox.com/users/3/friends");
$obj = json_decode($json);
for ($i=0; $i < count($obj); $i++) {
echo $obj[$i]->Id;
echo $obj[$i]->Username;
}
The data is actually JSON. You can get it like this :
$jsonString = file_get_content('http://api.roblox.com/users/3/friends');
$data = json_decode($jsonString, true);
$username = $data[14]['username']; // 14 is your desired index
$id = $data[14]['id'];

T_VARIABLE parse error [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 saw here about my problem PHP Script to Edit DNS Records in CPanel but When I try to use the dnsclass.php.
I can create a object like this:
$zones = new zone_records("cpaneluser", "pass", "website_to_login", "domain_of_records")
But I can't use this:
$zones->addrecord($type, $target, $name, $ttl)
I'm having this problem :
Parse error: syntax error, unexpected T_VARIABLE in /home/mcser325/public_html/test.php
My code:
include 'classdns.php';
$zones = new zone_records("**", "**", "**", "**")
$zones->addrecord("**", "**", "**", "**")
There is no semicolon at the end of the statement which is causing the error.

Categories