PHP - Stdclass String
Hello together, i ve got a script what returns the html code from anonther side. $CR_URL= 'https://nomoreangel.de/api-reader/?apiid=cr-de-148-f9ea2d50ee296914d740c8bde66cc3bb761b1560&rawOut=on'; $html = file_get_html($CR_URL); $ret = $html->find('pre', 0); echo $ret; echo $ret gives me following Output:
stdClass Object ( [repaired_defenses] => Array ( ) [generic] => stdClass Object ( [cr_id] => f9ea2d50ee296914d740c8bde66cc3bb761b1560 [event_time] => 2021-03-05T23:17:59+01:00 [event_timestamp] => 1614982679 [combat_coordinates] => 1:22:11 [combat_planet_type] => 1 [combat_rounds] => 0 [loot_percentage] => 75 [winner] => attacker [units_lost_attackers] => 0 [units_lost_defenders] => 0 [attacker_count] => 1 [defender_count] => 1 [loot_metal] => 843324 [loot_crystal] => 431284 [loot_deuterium] => 226605 [combat_honorable] => [attacker_honorable] => [attacker_honorpoints] => 0 [defender_honorable] => [defender_honorpoints] => 0 [moon_created] => [moon_chance] => 0 [moon_size] => 0 [moon_exists] => 1 [debris_metal_total] => 0 [debris_crystal_total] => 0 [debris_metal] => 0 [debris_crystal] => 0 [debris_reaper_metal_retrieved] => 0 [debris_reaper_crystal_retrieved] => 0 [debris_pathfinder_metal_retrieved] => 0 [debris_pathfinder_crystal_retrieved] => 0 [wreckfield] => Array ( ) ) [attackers] => Array ( [0] => stdClass Object ( [fleet_owner] => Kurzer [fleet_owner_id] => 110574 [fleet_owner_character_class_id] => 3 [fleet_owner_coordinates] => 1:170:15 [fleet_owner_planet_type] => 1 [fleet_owner_planet_name] => suche_deut [fleet_owner_alliance] => Eis Kalte Engel [fleet_owner_alliance_tag] => EKE [fleet_armor_percentage] => 210 [fleet_shield_percentage] => 210 [fleet_weapon_percentage] => 220 [fleet_composition] => Array ( [0] => stdClass Object ( [ship_type] => 219 [armor] => 7130 [shield] => 310 [weapon] => 640 [count] => 311 ) ) ) ) [defenders] => Array ( [0] => stdClass Object ( [fleet_owner] => Croupier [fleet_owner_id] => 114969 [fleet_owner_character_class_id] => 3 [fleet_owner_coordinates] => 1:22:11 [fleet_owner_planet_type] => 1 [fleet_owner_planet_name] => Suche deut [fleet_owner_alliance] => [fleet_owner_alliance_tag] => [fleet_armor_percentage] => 120 [fleet_shield_percentage] => 120 [fleet_weapon_percentage] => 120 [fleet_composition] => Array ( ) ) ) [rounds] => Array ( ) ) Now i want to get access to these Object, but because it is a string, i can t access the values.
Can somebody help me? Similar Tutorialswhy do i keep getting this error from line 7? Object of class stdClass could not be converted to string Code: [Select] <?php include_once"../includes/db_connect.php"; $item_number="2"; $custom="54298"; $query=mysql_query("SELECT `prodID`, `quanity` FROM `cart` WHERE `sessID`='$custom'") or mysql_error(); while($cart=mysql_fetch_object($query)){ mysql_query("INSERT INTO `orderItems` ( `id` , `orderInfoID` , `productID` , `quanity` ) VALUES ('', '$item_number', '$cart-> prodID', '$cart->quanity');"); } mysql_query("UPDATE `cart` SET `show`='1' WHERE `sessID`='$custom'"); ?> I have been trying to access an stdClass I can't. This stdClass gets returned from a method in a class . below the query is right all I want to do is put admi into a session var but I can't seem to access the obj. I can print_r and it displays. I am sure that it is easy. being new to PDO I am getting lost at times. Any help would be greatfully recieved Code: [Select] stdClass Object ( [Admin_Level] => admi ) Hi all, I need some help with my code as I have a hard time with fetching the value from the stdclass. I am using json data to convert it to PHP so I would like to fetch the "appears" data from the stdclass object. When I try this: echo $data->appears;
I'm getting this: Notice: Trying to get property of non-object in /home/username/public_html/foldername/script.php on line 22
I have also tried this: echo $data[0]->appears->value;
And this: echo $data->appears[0]->value;
I am still get the same error so I dont know what to do to resolve it.
Full code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $json = '{"data":{"185.220.101.46":{"domains_count":0,"domains_list":null,"updated":"2019-12-02 22:04:25","spam_rate":1,"frequency":6827,"frequency_time_24h":106,"frequency_time_1h":2,"network_type":"hosting","in_antispam":1,"in_security":0,"appears":1,"country":"DE","submitted":"2018-01-11 20:34:37","frequency_time_10m":2,"sha256":"e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248"}}}'; // Converts it into a PHP object $data = json_decode($json, true); //print_r($data); echo $data["appears"]->value ."<br/>"; //var_dump($data[1]->{'updated'}); //echo $data->updated[1]->value; ?>
STDClass object: Array ( [data] => Array ( [185.220.101.46] => Array ( [domains_count] => 0 [domains_list] => [updated] => 2019-12-02 22:04:25 [spam_rate] => 1 [frequency] => 6827 [frequency_time_24h] => 106 [frequency_time_1h] => 2 [network_type] => hosting [in_antispam] => 1 [in_security] => 0 [appears] => 1 [country] => DE [submitted] => 2018-01-11 20:34:37 [frequency_time_10m] => 2 [sha256] => e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248 ) ) )
Var_dump: array(1) { ["data"]=> array(1) { ["185.220.101.46"]=> array(15) { ["domains_count"]=> int(0) ["domains_list"]=> NULL ["updated"]=> string(19) "2019-12-02 22:04:25" ["spam_rate"]=> int(1) ["frequency"]=> int(6827) ["frequency_time_24h"]=> int(106) ["frequency_time_1h"]=> int(2) ["network_type"]=> string(7) "hosting" ["in_antispam"]=> int(1) ["in_security"]=> int(0) ["appears"]=> int(1) ["country"]=> string(2) "DE" ["submitted"]=> string(19) "2018-01-11 20:34:37" ["frequency_time_10m"]=> int(2) ["sha256"]=> string(64) "e39d4a9be2f210d1a75ba2b5ece08a4b35e99002b03aeb6ceaad1d98de87c248" } } }
Can you please show me an example how I can fetch the `appears` from the stdclass object? Any advice would be much appreciated. Edited December 2, 2019 by mark107Hi guys, I have below values in array Code: [Select] stdClass Object ( [Category] => stdClass Object ( [ChildCategoryDescription] => 50s / 60s ERA [ChildCategoryID] => 87 [GrandchildCategoryDescription] => - [GrandchildCategoryID] => 25 [ParentCategoryDescription] => CONCERTS [ParentCategoryID] => 2 ) [Description] => Tony Bennett [ID] => 1073 [HomeVenueID] => 0 ) When am calling Desciption object by $resultsObj->Description then i got the result " Tony Bennett" but i do not know to get the value GrandchildCategoryID . Just i tried this Code: [Select] echo $resultsObj->$resultsObj->ParentCategoryID and i got below error. Catchable fatal error: Object of class stdClass could not be converted to string in D:\Program Files\xampp\htdocs\t1\genericLib.php on line 255. How i can get this value... I am using the following code
foreach ($fbdata->data as $post ) { $posts .= '<li>'; $posts .= '<p>' . $post->message . '</p>'; $posts .= date('d-M-y', strtotime($post->created_time)); $posts .= '</li>'; } and if the message propeerty doesn't exist I get the message above. Any ideas on the best way to fix this? error Notice: Undefined property: stdClass::$post_url in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 133 Notice: Undefined property: stdClass::$post_title in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 133 Notice: Undefined property: stdClass::$post_date in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 137 Notice: Undefined variable: fb in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 138 Notice: Undefined variable: tw in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 140 Posted Posted on | Facebook Facebook Twitter Twitter Notice: Undefined property: stdClass::$post_content in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 153 Notice: Undefined property: stdClass::$post_url in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 154 http://www.socialnewsoffice.com/blog_posts?start=0&api_key=b5cbd66dca99c49d1a6c3d ive used this a my json Code: [Select] //check if you have curl loaded if(!function_exists("curl_init")) die("cURL extension is not installed"); function Social_News_Office($action, $api_key){ // jSON URL which should be requested $json_url = $action.'&api_key='.api_key.''; // Initializing curl $ch = curl_init( $json_url ); // Configuring curl options $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: application/json') , ); // Setting curl options curl_setopt_array( $ch, $options ); // Getting results return $result = json_decode(curl_exec($ch)); // Getting jSON result string } $blog_posts = Social_News_Office('http://www.socialnewsoffice.com/blog_posts?start=2&display=6', api_key); foreach($blog_posts as $post) { echo '<!--START OF POST--> <div class="post"> <h2 class="post-heading"><a href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/">' . strip_tags($post->post_title) . '</a></h2> <!--START OF BLOG INFO--> <p class="meta"> <img alt="Posted" class="meta-img" src="http://www.socialnewsoffice.com/blog-images/time.png"> Posted on ' . $post->post_date . ' | <a target="_blank" href="'.$fb.'" class="socialusers icon Facebook"> <img alt="Facebook" src="http://www.socialnewsoffice.com/blog-images/facebook.png"> Facebook </a> <a target="_blank" href="http://twitter.com/#!/'.$tw.'" class="socialusers icon Twitter"> <img src="http://www.socialnewsoffice.com/blog-images/twitter.png" alt="Twitter" align="baseline"> Twitter </a> </p> <!--START OF POST CONTENT--> <div class="post-content">'; if(!empty($post->article_img)){ echo '<a href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/"> <img alt="' . strip_tags($post->post_title) . '" class="post-thumbnail" src="' . BLOG_BASE_URL . 'sno-blog/thumbnail.php?file='.$post->article_img.'&width=240&height=160" title="' . strip_tags($post->post_title) . '"></a>'; } echo '<p>' . $post_content = substr(strip_tags($post->post_content,'<p><br><a>'),0,266).'...' . '</p> <a class="read-more" href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/">Continue reading</a> <div class="clear"></div> </div><!--END OF POST CONTENT--> </div><!--END OF POST-->'; } Hi i'm struggling to pull data from an stdClass Object which searches google for an item. This is the code that pulls out the information Code: [Select] <?php $encoded_response = file_get_contents("https://www.googleapis.com/shopping/search/v1/public/products?key=AIzaSyDCrZzoEB46bliROIn8JgOImm0B5YvxbVY&country=US&q=0014633144796"); $response = json_decode($encoded_response); print_r($response); ?> (can be seen at:http://www.rafoggin.com/Shrop/googletestapi.php i've tried Code: [Select] $object = $result[0]; $print = $object->kind; echo $print and Code: [Select] foreach ($result->product as $print) { echo $print->googleId;and many other variations but can't get it to work. ideally i'd like to pull the images out, but the structure confuses me. Your help is really appreciated, I can't figure this out. I have a stdClass Object Multi Dimensional Array that I need to dissassemble into variables but dont know how to pull the data. The array looks like this: Code: [Select] stdClass Object ( [results] => Array ( [0] => stdClass Object ( [address_components] => Array ( [0] => stdClass Object ( [long_name] => 1600 [short_name] => 1600 [types] => Array ( [0] => street_number ) ) [1] => stdClass Object ( [long_name] => Pennsylvania Ave NW [short_name] => Pennsylvania Ave NW [types] => Array ( [0] => route ) ) [2] => stdClass Object ( [long_name] => Northwest Washington [short_name] => Northwest Washington [types] => Array ( [0] => neighborhood [1] => political ) ) [3] => stdClass Object ( [long_name] => Washington [short_name] => Washington [types] => Array ( [0] => locality [1] => political ) ) [4] => stdClass Object ( [long_name] => District of Columbia [short_name] => DC [types] => Array ( [0] => administrative_area_level_1 [1] => political ) ) [5] => stdClass Object ( [long_name] => United States [short_name] => US [types] => Array ( [0] => country [1] => political ) ) [6] => stdClass Object ( [long_name] => 20500 [short_name] => 20500 [types] => Array ( [0] => postal_code ) ) ) [formatted_address] => 1600 Pennsylvania Ave NW, Washington, DC 20500, USA [geometry] => stdClass Object ( [location] => stdClass Object ( [lat] => 38.8987149 [lng] => -77.0376555 ) [location_type] => ROOFTOP [viewport] => stdClass Object ( [northeast] => stdClass Object ( [lat] => 38.900063880291 [lng] => -77.036306519708 ) [southwest] => stdClass Object ( [lat] => 38.897365919709 [lng] => -77.039004480291 ) ) ) [partial_match] => 1 [types] => Array ( [0] => street_address ) ) ) [status] => OK ) Really I need to start with pulling the lat and lng from the location. No clue how to get to this data. hi, very strange issue. when I create test e-mail or I will forward the specific e-mail, the script works correctly - saves attachment into server disk. now, when I configure to check another mailbox, it gives me error: Num Messages 11 Fatal error: Cannot use object of type stdClass as array in /test/emailattach/index.php on line 34 index.php: Code: [Select] <?php $mbox = imap_open("{mail.server.com:143}", "email@email", "XXX") or die('Cannot connect to mail: ' . imap_last_error()); // make connection with mailbox and check # messages if ($hdr = imap_check($mbox)) { echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>"; $msgCount = $hdr->Nmsgs; } else { echo "failed"; } $overview=imap_fetch_overview($mbox,"1:$msgCount",0); $size=sizeof($overview); // get message info for($i=$size-1;$i>=0;$i--) { $val=$overview[$i]; $msg=$val->msgno; $from=$val->from; $date=$val->date; $subj=$val->subject; $seen=$val->seen; $from = ereg_replace("\"","",$from); // Check for attachements and store them $struct = imap_fetchstructure($mbox,$msg); $contentParts = count($struct->parts); if ($contentParts >= 2) { for ($ix=2;$ix<=$contentParts;$ix++) { $att[$ix-2] = imap_bodystruct($mbox,$msg,$ix); } for ($k=0;$k<sizeof($att);$k++) { if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") { if ($att[$k]->parameters[1]->value != "") { $FileName[$k] = $att[$k]->parameters[1]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); } } elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") { $FileName[$k] = $att[$k]->parameters[0]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); $fileContent = imap_fetchbody($mbox,$msg,$file+2); $fileContent = imap_base64($fileContent); $localfile = fopen("$FileName[$k]","w"); fputs($localfile,$fileContent); fclose($localfile); } } } } imap_close($mbox); ?> Could there be some encoding issue? with thanks, Margus Hi Guys, I need help I have setup a code recently : this is the code : $za['MIN(spec_positionid)'] and it gave me an error saying : Cannot use object of type stdClass as array but if I change to this : $za->spec_positionid it works, but I need to get the MIN value from the database. can someone please help. this is very urgent for me..... Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks
In PHP Version 8.0 shows error as : In previous versions of PHP it does not show any error. Please resolve the issue. Ok... I had typed this post out ONCE already and when I clicked REFRESH IMAGE to get a diff captcha it ERASED MY POST LMAO this is not my night.... What I need help with is probably more simple then I can even think right now - ive been digging at this for 3 hrs now and im out of time for the night I have a DB Record storing ID's between PIPES | when the initial entry is made in DB it stores it like so |47| NOTE: the number could be different these are ID's number doesnt matter its just between Pipes When the second entry is added its added like so |47||67| say we have a total of 5 Entries |47||67||82||55||69| I need to find ID 82 in that string and it has to be between Pipes Find 82 in data between | and return that ID 82 I am putting between pipes because the ID's can be duplicate digits in different lengths so say I have 8 as my ID and down the string i have another id as 88 -- I cant possibly find the correct ID without some sort of seperation character so i used Pipes soo my end goal is the ability to search and if true or false do action if ($result == $find_id){ echo "ID is there"; }else{ echo "NOT THERE -- Adding it"; } Any help is appreciated guys Thanks SangrelX I am looking for a date within larger string, lets say the date is December 4, 2010. To find it I use pattern and function below: $Pattern='/[(January|February|March|April|May|June|July|August|September|October|November|December)] \d, \d\d\d\d/i'; preg_match_all($Pattern, $String, $Matches, PREG_OFFSET_CAPTURE, $NumberPosition); The function finds the dates within the string but to my supprise the result I get in $Matches is: r 4, 2010 What I would like to get is: December 4, 2010 but don't know how it should be fixed. I thought that with the pattern I am using but obviously that is not the case. |