PHP - Array Not Working Outside Of Curly Brackets
Hi There, I'm trying to get the following array to work as a separate include php file to make the HTML easier to follow. Within the HTML it has been working fine, as the "echo $tdata_consent Variable is within the main curly brackets. As soon as I move the variable outside of the brackets I only get 1 item from the array rather than all of the items. $projects_const = array(); $required_const = ['Consent']; $colors_const = array_combine($required_const, ['bg-danger text-white font-weight-bold'] ); $xml_const=simplexml_load_string($jobs_task_response) or die("Error: Cannot create object"); foreach($xml_const->Jobs->Job as $item_const) { if (in_array((string)$item_const->State, $required_const)) { $projects_const[] = array( 'job_no' => (string)$item_const->ID, 'job_name' => (string)$item_const->Name, 'job_start' => date('d/m/Y', strtotime($item_const->StartDate)), 'job_due' => date('d/m/Y', strtotime($item_const->DueDate)), 'job_status' => (string)$item_const->State, 'job_staff' => (string)$item_const->Assigned->Staff->Name, ); } } usort($projects_const, function($a,$b) {return $b['job_due'] <=> $a['job_due']; } ); foreach ($projects_const as $proj_const) { $job_no =$proj_const['job_no']; $job_name =$proj_const['job_name']; $job_status =$proj_const['job_status']; $job_staff =$proj_const['job_staff']; $job_due =$proj_const['job_due']; $clr_1 = $colors_const[$job_status]; $tdata_const = ''; $tdata_const .= "<div class='row no-gutters'>"; $tdata_const .= "<div class='col-sm bg-white border rounded'><a href='managejob.php?job_id=$job_no' class='text-left ml-1'><strong>$job_no</strong></a></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_name</p></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'>" . state_dropdown_1($job_no, $job_status, $clr_1) . "</div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_status</p></div>"; $tdata_const .= "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_staff</p></div>"; } echo $tdata_const; Any thoughts would be much appreciated. Thanks in Advance. Similar TutorialsHi Guys Quick noob question. I am still fairly new to oop and i'm trying to also build my first simple mvc to learn about that too. I came across some syntax use in a tutorial that works but i don't really understand why and don't know what this is called to search for it on google. I've instantiated the class and then i pull out and explode the url to make controller or function calls in the mvc. The noob bit i don't understand is this Code: [Select] $controller->{$url[1]}(); Why do the curly brackets allow you to place a variable name? And what is this type of syntax called so i can read about it. Any help would be massively appreciated! Drongo Hi all I'm quite a competent PHP coder but where it comes to preg_match I prefer to be ignorant, because I can't get my head around the patterns. Basically, I'm working with a script that someone else has written, and I'm coming across problems because the URL that is being validated sometimes has curly brackets '( )' in it (these are image file names generated by an internal system). I have the pattern, how do I modify this to allow curly brackets? On some occasions, the urls have just the opening or just the closing, so its never the complete set. if someone could give me an indication with this, because I'm clueless! Thanks in advance! Ste pattern: Code: [Select] $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/'; is there any way to POST array without brackets in name attribute? i.e. instead of "product[]" have "product" in the <input name="<NAME>"> Thanks in advance CSJakharia the code is simple but the output is wrong. Code: [Select] $str = <<<EOF a:2:{s:7:"visible";a:7:{i:0;s:5:"email";i:1;s:5:"print";i:2;s:8:"facebook";i:3;s:4:"digg";i:4;s:11:"stumbleupon";i:5;s:7:"twitter";i:6;s:6:"reddit";}s:6:"hidden";a:0:{}} EOF; echo "<textarea rows='10' cols='90'>";print_r(unserialize($str));echo "</textarea>"; the ouput is Code: [Select] Array ( [visible] => Array ( [0] => email [1] => print [2] => facebook [3] => digg [4] => stumbleupon [5] => twitter [6] => reddit ) [hidden] => Array ( ) ) This is wrong I need something like this: Code: [Select] array ( 'visible' => array ( 0 => 'email', 1 => 'print', 2 => 'facebook', 3 => 'digg', 4 => 'stumbleupon', 5 => 'twitter', 6 => 'reddit', ), 'hidden' => array ( ), ) What am I doing wrong? How do I fix it? I didn't know how to describe this, so please excuse my title. As most of you know, this is possible: foreach($items as $key => $item) { ${$key} = $item; } // I would then be able to access it like so: $key // or whatever the value of "$key" is. However, how could I append something extra to the ${$key} variable? Instance: foreach($items as $key => $item) { $my_{$key} = $item; // or ${$key}_arr = $item; } // So that the end result of my variable becomes like so: $my_key // or $key_arr // Instead of just $key // or whatever the value of "$key" is. Is there a known method for this? Any input is appreciated, thank you. Hi Guys I am having trouble with a mysql regexp expression called through php. I am not sure but I suspect its to do with the {} in the mysql code and PHP parsing them incorrectly. Here is my code snippet: $q = mysql_real_escape_string($_POST['keyword']); $limit = 10; //limit number of responses from dictionary $remainder = 11 - strlen($q); if ($q) { $qy = "SELECT * FROM dict_list WHERE UCASE(word) <> UCASE('$q') AND (word REGEXP '^$q.{$remainder}') LIMIT $limit"; $query = mysql_query($qy); ... What I want to do is this: a user types in a word. I then want to query a dictionary table called dict_list for all matches of the this word up to 11 characters max. Example: if $q was the word aero then the response would be all words beginning with aero and up to a max of 11 characters. That is why IU thought I could calculate length of $q and from this get the $remainder = 11 - strlen($q) then in the REGEXP use .{$remainder} but when testing if I echo out the query $qy the curly braces will not show on screen. Any help would be greatly appreciated. I hope this is posted in correct location. Apologies if not. Thanks, Fergal. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=353613.0 $text = "wow {one|two|three}fsasfa happy ness"; preg_match('/\b{*+}\b/i', $text, $matches); print_r($matches); Basically, $matches will contain "one|two|three" - but all I got is an array with "}" function send_msg($sender , $message){ if(!empty($sender) && !empty($message)){ $sender = mysql_real_escape_string($sender); $message= mysql_real_escape_string($message); $query = "INSERT INTO `chat`.`chat` VALUES (null , '{$sender}' , '$message')"; // Difficulty on THIS LINE !!!! if($run = mysql_query($query)){ return true; }else{ return false; } } why is '{$sender}' given the curley brakets ????? and why is message not given the same brackets ? also why is this function used ? i.e. mysql_real_escape_string , i know what it does , but is it to prevent SQL injection. Hi Yes I start a new thread, this is probably the correct one. hi silly little question but if I want to bracket something inside PHP how do I do it eg my code is Code: [Select] <th class="alignright"><?php echo $ass_descrip; ?> (<?php echo $ass_accro ; ?>) <?php echo FindTypeName ($type_id); ?></th> printing out British Eventing (BE) But the brackets at the moment are outside the PHP I want to put a conditional on it and include the brackets inside my conditional statement.? For example. I have the following: Andrew (Age 19) How would I get the content between the brackets, Age 19 using preg_match_all or a similar function? Thanks very much Hi Ive been trying to solve this problem for a few hours but am having no luck so would appreciate any help Im looking for a function/way of extracting info from a dropdown list when a form is submitted. The form field has a name and email address i.e John (john@smith.com) and i just need the email address part to submit into a mysql database. I tried using the explode() function but this didnt work. Any ideas? Cheers Andy Code: [Select] 30|24|17,5|4|20,15|13|33,15|22|33,9|20|22 Let's say my output is that, Realistically every 3numbers is 1 Ticket they are seperated by a "," (comma) I want to wrap parenthesis around them so the output would look like this Code: [Select] (30|24|17) (5|4|20) (15|13|33) (15|22|33) (9|20|22) Now would I have to use regex.. or not cuz regex is extremely difficult Thanks I'm looking for a method to replace everything between brackets. The patterns that I'm looking for are defined: "/\[([2-9TJQKA][hdcs])\]/" The pattern inside the bracket could accur 2 or even 3 times inside the brackets. For example first occurance would be [Ac Kd], here I want to replace Ac into an imge and Kd too. Later in the text I will most of the time get 3 sets, instead of two: [Jc Td 9d]. The sets always consist of [2-9JQKA][hdcs] and also in this order. Another example: [2d 2s 2h], or [3s 4h 5c]. If I use the following function, it would not work optimally because some texts do contain some of those sets which should not be converted, ONLY the sets between the brackets: $haystack = setReplace($haystack); function setReplace($haystack) { $array = array("2s", "2h", "2d", "2c", "3s", "3h", "3d", "3c", "4s", "4h", "4d", "4c", "5s", "5h", "5d", "5c", "6s", "6h", "6d", "6c", "7s", "7h", "7d", "7c", "8s", "8h", "8d", "8c", "9s", "9h", "9d", "9c", "Ts", "Th", "Td", "Tc", "Js", "Jh", "Jd", "Jc", "Qs", "Qh", "Qd", "Qc", "Ks", "Kh", "Kd", "Kc", "As", "Ah", "Ad", "Ac"); for($i=0;$i < count($array);$i++) { $result = str_replace($array[$i], "<img src=\"/images/".$code[$i].".png\">",$haystack); } return $result; }Any ideas? Edited by dde, 20 January 2015 - 10:21 AM. Is making a double elimination tournament style bracket system capable of being done in php? After dealing with numerous very well qualified programmers to only turn down the project due to difficulty or lack of a solution I am curious if anyone has figured this out. I have run across a few sites that have some programs but all turn up to have some issues with the pairing of teams. Please let me know! If you know the solution, we can work something out as far as payment. This is not a looking for work post, but merely a "can it be done" and if so and you are willing to share the info, it would be greatly helpful. Quote Hi Guys I'm trying to remove the brackets around a string with preg_replace I seem to able to remove the first bracket but not the last. Here are my attempts..... heres the string Code: [Select] $testemail = '(bobbyboo@sample.com.au)'; echo $testemail; $testemail2 = trim(preg_replace('/^[\(]/', '', $testemail)); echo $testemail2."<br />"; $testemail3 = trim(preg_replace('/$\)/','', $testemail2)); echo $testemail3."<br />"; Hello all! I cannot seem to figure out a way to pass an object from one page to another. Now, my flow may be way off, and if it is, please do advise. I want to have a form for username/password log in. When the submit button is hit, it takes those values, finds the matching user in the database, and returns the user object. We'll call him user_object Now, I want to bring up another page, that allows user_object to enter in additional information (Event details). After it does this, it writes those Event Objects into the database. My problem is: I need the ID Object attached to user_object while inserting the Event Objects into the database. The user_object and Event Objects values are assigned from two separate forms and two separate submit buttons. How do I pass this information? I don't want to use session because I have a lot of objects and do not want to serialize and unserialize all the time. I also read that $_GET is a security risk. Thanks in advance for any help! This is the basic logic of the code I am trying: Code: [Select] <html form whatevs post> <php object_one if (creds_match) { build_object from db } else "Wrong info, dude" ?></endhtml stuffs> Code: [Select] <html form whatevs post> <php object_two if (post!empty) { object_two = poststuff } assign object_two object_one's _id insert object_two into db ?></endhtml stuff> How do I keep the values assigned in section one, and send them or be able to use that same variable in section 2? I've noticed some people don't use { } when they right statements, when I first started learning PHP a couple years ago, I thought you HAD to put the curly brackets, but apparently not, how does this work and why don't some people use them in their scripts? Quotation marks are confusing me.
What do you guys use when it comes to quotation marks?
In HTML attributes and throughout the bodies of my web pages, I use the HTML entity ("). For example:
<a href="" title="Read "Article Name""> <p>In his new book, he says: "This is a quote."</p>I thought that this is the best practice. However, today, I read that it's perfectly safe to use straight quotes (") in the body, and that I should use the HTML entity only in HTML attributes. Is that correct? But what if I want to use curly quotes in the body instead of straight quotes? Should I always use the HTML entities for curly quotes (“ and ”), or can I also safely use the characters (“”)? I heard that straight quotes are safe in all browsers, even if you don't specify the character set of your web pages, but that curly quotes are only safe if you specify the character set or if you use the HTML entities. Is that true? And what about the <q> tag? Apparently, it's compatible with all browsers but they treat it differently. Edited by Fluoresce, 30 August 2014 - 07:37 AM. |