PHP - Kind Of Lost On How To Apporach This - Array Into Interger / Removing Quotes?
Well, In my DB i have user items as follows:
Code: [Select] 13,12,11,9,27,15,16,22,21,23,24,26,29,30,31,32,33 Each ID is a user item that has been imploded to be sent to the DB. Well, I', trying to take them out of the DB now, and I'm having a small problem turning them back into integers. Here's what I've done. Code: [Select] $items = explode(",", $row['user_item_id']);So I get: Code: [Select] 0 => string '13' (length=2) 1 => string '12' (length=2) 2 => string '11' (length=2) 3 => string '9' (length=1) 4 => string '27' (length=2) 5 => string '15' (length=2) 6 => string '16' (length=2) 7 => string '22' (length=2) 8 => string '21' (length=2) 9 => string '23' (length=2) 10 => string '24' (length=2) 11 => string '26' (length=2) 12 => string '29' (length=2) 13 => string '30' (length=2) 14 => string '31' (length=2) 15 => string '32' (length=2) 16 => string '33' (length=2) Then I do this: Code: [Select] foreach($items as $item){ var_dump($item); $sql = 'SELECT * FROM `MYTABLE` WHERE item_tab = '.$tab_id.' AND item_id = '.$item.' AND item_pose =0'; } and get this: Code: [Select] string '13' (length=2) string '12' (length=2) string '11' (length=2) string '9' (length=1) string '27' (length=2) string '15' (length=2) string '16' (length=2) string '22' (length=2) string '21' (length=2) string '23' (length=2) string '24' (length=2) string '26' (length=2) string '29' (length=2) string '30' (length=2) string '31' (length=2) string '32' (length=2) string '33' (length=2) Now, this works how I want it to except, I want a integer value not a string. What would be the best way to approach this? Similar TutorialsThis code only works in firefox <a onMouseout='hidetooltip()' onMouseover='tooltip(\"<img src=img/heroes/$hero.gif\")' href='hero.php?hero=$hero'>Text</a> Btw, I use this in echo (php). How to get quotes (triple) on <img src= ? I also have tried <img src='img/heroes/$hero.gif' But only works on FireFox http://content.screencast.com/users/DeviousDan/folders/Jing/media/a563187c-93fe-4ec7-b496-41e50554b639/2011-01-02_2220.png As you can see, I print_r the results array and it has a key of aim, I then try to access the aim value on line 44 and as you can see, it's an undefined Index. I've officially forgotten all basics of PHP, any fresh eyes wanna give some insight? Thanks. Hi! I need a little bit coding help here. I have a table: Numbers, Active Under numbers can be 10000, 10001, 10002, 10003, 10004, 10005 and active can be 1 or 0, depends on is this row active or not. Now, i need to check, is there any numbers lost, i mean, (for example) in table i have numbers 10002, 10000 and 10005 Can somebody make script, what finds those lost numbers, in this case those a 10001, 10003 and 10004. All the best: Mart After getting valuable help from DavidAm and wildteen88 I am left with this last piece to the puzzle: I have created a function which identifies the names of multi-value checkbox fields used on a Post page where a form just filled out has been saved in a serialized array which will contain associative arrays wherever the checkboxes have been selected. Now I need for the checkbox associative arrays returned on this Review before-final-saving-page to be detected or identified and then Changed to a comma-delimited array, or maybe it just gets converted to one string with commas separating what were parts of the array--I am not sure about that. At any rate, here are the functions that WORK to do this---but they depend on knowing the specific checkboxes that will show up ahead of time: $postvals['cp_checkbox_amenities']= implode(',', $_POST['cp_checkbox_amenities']); $postvals['cp_checkbox_days']= implode(',', $_POST['cp_checkbox_days']); $postvals['cp_checkbox_3']= implode(',', $_POST['cp_checkbox_3']); So I created a function which polls the form and finds the specific names of the checkboxes used on this page--the function ends like this: $results = $wpdb->get_results($sql); if($results) { foreach ($results as $result): // now grab all ad fields and print out the field label and value echo '<li><span>' . $result->field_name . '</li>'; endforeach; } else { echo __('No checkbox details found.', 'cp'); } } } This returns the following: <li><span>cp_checkbox_help</span></li><li><span>cp_checkbox_charley</span></li><li><span>cp_checkbox_hello</span></li> </li> So, I then tried to REPLACE the hard-code functions I show above that take the checkbox arrays and implode them for saving when this form is updated as comma limited values. I tried various versions of this using the same loop that produced the <li> list with $result->field_name : foreach ($results as $result): // now grab all ad fields and print out the field label and value $postvals['. $result->field_name .']= implode(',', $_POST[ '. $result->field_name .']); endforeach; } else { echo __('No checkbox details found.', 'cp'); } } } Every different way I try to get something either errors out or does not perform the Implode, or notifies me that the Implode is creating problems. SOMEHOW, dynamically for each loop I need for a ' single quote mark to appear on each side of $result->field_name so that I have dynamically written in the php code the equivalent to $postvals['cp_checkbox_amenities']= implode(',', $_POST['cp_checkbox_amenities']); $postvals['cp_checkbox_days']= implode(',', $_POST['cp_checkbox_days']); $postvals['cp_checkbox_3']= implode(',', $_POST['cp_checkbox_3']); the $result->field_name gives me a cp_checkbox_3 or a cp_checkbox_amenities, etc,, but I cannot break it down so that $postvals['$result->field_name']= implode(',', $_POST['$result->field_name']); WORKS and I have tried with [PHP? echo ''' .$result->field_name . ''' ?>] and other ways. Incidentally, ", double quotes don't play nice on this server with PHP 5. And I have tried combinations of " ' double quote then single quote and on the other side ' " inside the associative array brackets.. nothing works--either I get errors, implode warnings, or the arrays of these checkboxes do not get changed to comma delimited arrays if the page loads and saves without errors. I'd appreciate receiving what must be an elegantly simple solution! 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. The fancy-looking quotes won't insert into my DB, so I'm trying to convert them to %93 & %94 or normal quotes.
Nothing I've tried works.
Code:
$fancy=" “test” "; $fixed=htmlentities($old, ENT_QUOTES); echo "fancy: $fancy<br>"; echo "fixed: $fixed"; Results: fancy: “test” fixed: I want $fixed to be %93test%94, or even "test" would work. Edited by rwmaho, 18 October 2014 - 01:28 PM. Hello everyone! This is my first post. I am very new to php and mysql and coding in general. It has not been made 100% clear to me as to when I should use single quotes, double quotes, and {}. From what I gather you use single quotes for literal interpretation... so if you put something like a variable in single quotes and echoed it, it would literally echo it as it is written and not the value of the variable. in double quotes, I gather that it will echo the value of the variable. as for {} I am unclear as to when to use the curly brackets for a variable. I am assuming if you had a statement in single quotes and you put a variable in curly brackets you would get the value of the variable?
Edited by LazerOrca, 25 November 2014 - 11:20 PM. I'm having problems running a php program on my Linux box which runs fine on my Windows box.
I traced the problem down to a line of code:
$higherValue = 0xFFFFFFFF;
This should be an maximum unsigned int value of 4294967295, but PHP doesn't handle unsigned int so it should convert it to a float. This is not happening on my system. Instead it is just converting it to a max int value of 2147483647.
I wrote a small php test script:
var_dump(0x00000000); I don't think I've asked this before have I?? can someone give me an internet KB that gives me all scenarios that warrant using singles or doubles? as in, wrapping values, variables, and why I need to do either, and when, etc, etc....? thanks Edited March 29 by ajetrumpetHello. This one is driving me up the wall. It used to work, I have a sports league database (MsSql) and one of the tables contains team Captain's first name, last name, etc.. To create a unique but simple login, the query searches for the captain's first initial of their first name + lastname + league. However since there is the remote possibility of two similar usernames (i.e. David Smith) if the last name is found, the query adds an integer to the end of the last name. So the result would look like this: DSmithM4A At the moment, my database is completely blank. However what is happening when I run the query below is I get: DSmith1M4A Can someone figure out why this code is not working correctly? If there is not more than one "Smith" no integer is supposed to be returned. There is something in the "Captain Count" that I think is not working correctly. Code: [Select] /* * Gather captian information */ $strCaptainFirstInitial = substr($arrPost['cpt_first'],0,1); $strCaptainLastName = preg_replace("/[^a-zA-Z]/","",$arrPost['cpt_last']); $strCaptainName = strtolower($strCaptainFirstInitial.$strCaptainLastName); $sqlCaptainSearch = sprintf ( $strCaptainSearch, $strCaptainName ); $resCaptainSearch = mssql_query($sqlCaptainSearch,$conDB); /* * Create unique captain login and Password */ $strCaptainCount = (mssql_num_rows($resCaptainSearch) > 0) ? mssql_num_rows($resCaptainSearch) : "" ; $strLeagueTypeInitial = substr($arrLeagueSearch['type'],0,1); $strCaptainLogin = $strCaptainName . $strCaptainCount . $strLeagueTypeInitial . $arrLeagueSearch['size'] . $arrLeagueSearch['division']; Hey guys. How do you remove a specific element from an array? Lets say I have a string like this: $list = "guy,girl,boy,man,woman,lady"; Then I use explode to break it up into an array by commas: $listArray = explode(",",$list); Now $listArray contains everything. Now if I wanted to delete something specific from that array, how would I do that? So for example, I want to delete "man" out of the array. How do I do that without know its key? I used DOM to parse data from html, then I made the data go into an array. the array now looks like Array([0]->street[1]->city, st, zip[2]->phone[3]->fax) and it is quite a long array. The problem is that when there is no fax number on the html, it doesnt show the fax on the array, so when I am trying to loop through this in a table it is throwing off my cells. Is there a way to delete all entries in an array that include Fax:* ? Is there a way to exclude all nodes that have Fax* using DOM? My current DOM looks like... Code: [Select] $address = $xpath->query('//td[@id="addressText"]'); Hello I'm trying to remove null ou 0 values from my array but i can't get it to work properly This is my array
Array ( [0] => Array ( [0] => 2020-09-21 [1] => 3 ) [1] => Array ( [0] => 2020-09-23 [1] => 2 ) [2] => Array ( [0] => 2020-09-28 [1] => 3 ) [3] => Array ( [0] => 2020-09-30 [1] => 2 ) [4] => Array ( [0] => 2020-10-07 [1] => 2 ) [5] => Array ( [0] => 2020-10-12 [1] => 3 ) [6] => Array ( [0] => 2020-10-14 [1] => 2 ) [7] => Array ( [0] => 2020-10-19 [1] => 3 ) [8] => Array ( [0] => 2020-10-21 [1] => 2 ) [9] => Array ( [0] => 2020-10-26 [1] => 3 ) [10] => Array ( [0] => 2020-10-28 [1] => 2 ) [11] => Array ( [0] => 2020-11-02 [1] => 3 ) [12] => Array ( [0] => 2020-11-04 [1] => 2 ) [13] => Array ( [0] => 2020-11-09 [1] => 3 ) [14] => Array ( [0] => 2020-11-11 [1] => 2 ) [15] => Array ( [0] => 2020-11-16 [1] => 3 ) [16] => Array ( [0] => 2020-11-18 [1] => 2 ) [17] => Array ( [0] => 2020-11-23 [1] => 3 ) [18] => Array ( [0] => 2020-11-25 [1] => 2 ) [19] => Array ( [0] => 2020-11-30 [1] => 3 ) [20] => Array ( [0] => 2020-12-02 [1] => 2 ) [21] => Array ( [0] => 2020-12-07 [1] => 3 ) [22] => Array ( [0] => 2020-12-09 [1] => 2 ) [23] => Array ( [0] => 2020-12-14 [1] => 3 ) [24] => Array ( [0] => 2020-12-16 [1] => 2 ) [25] => Array ( [0] => 2021-01-04 [1] => 3 ) [26] => Array ( [0] => 2021-01-06 [1] => 2 ) [27] => Array ( [0] => 2021-01-11 [1] => 3 ) [28] => Array ( [0] => 2021-01-13 [1] => 2 ) [29] => Array ( [0] => 2021-01-18 [1] => 3 ) [30] => Array ( [0] => 2021-01-20 [1] => 2 ) [31] => Array ( [0] => 2021-01-25 [1] => 3 ) [32] => Array ( [0] => 2021-01-27 [1] => 2 ) [33] => Array ( [0] => 2021-02-01 [1] => 3 ) [34] => Array ( [0] => 2021-02-03 [1] => 2 ) [35] => Array ( [0] => 2021-02-08 [1] => 3 ) [36] => Array ( [0] => 2021-02-10 [1] => 2 ) [37] => Array ( [0] => 2021-02-17 [1] => 2 ) [38] => Array ( [0] => 2021-02-22 [1] => 3 ) [39] => Array ( [0] => 2021-02-24 [1] => 2 ) [40] => Array ( [0] => 2021-03-01 [1] => 3 ) [41] => Array ( [0] => 2021-03-03 [1] => 2 ) [42] => Array ( [0] => 2021-03-08 [1] => 3 ) [43] => Array ( [0] => 2021-03-10 [1] => 2 ) [44] => Array ( [0] => 2021-03-15 [1] => 3 ) [45] => Array ( [0] => 2021-03-17 [1] => 2 ) [46] => Array ( [0] => 2021-03-22 [1] => 3 ) [47] => Array ( [0] => 2021-03-24 [1] => 2 ) [48] => Array ( [0] => 2021-04-05 [1] => 3 ) [49] => Array ( [0] => 2021-04-07 [1] => 2 ) [50] => Array ( [0] => 2021-04-12 [1] => 3 ) [51] => Array ( [0] => 2021-04-14 [1] => 2 ) [52] => Array ( [0] => 2021-04-19 [1] => 3 ) [53] => Array ( [0] => 2021-04-21 [1] => 2 ) [54] => Array ( [0] => 2021-04-26 [1] => 3 ) [55] => Array ( [0] => 2021-04-28 [1] => 2 ) [56] => Array ( [0] => 2021-05-03 [1] => 3 ) [57] => Array ( [0] => 2021-05-05 [1] => 2 ) [58] => Array ( [0] => 2021-05-10 [1] => 3 ) [59] => Array ( [0] => 2021-05-12 [1] => 0 ) [60] => Array ( [0] => 2021-05-17 [1] => 3 ) [61] => Array ( [0] => 2021-05-19 [1] => 0 ) [62] => Array ( [0] => 2021-05-24 [1] => 3 ) [63] => Array ( [0] => 2021-05-26 [1] => 0 ) [64] => Array ( [0] => 2021-05-31 [1] => 3 ) [65] => Array ( [0] => 2021-06-02 [1] => 0 ) [66] => Array ( [0] => 2021-06-07 [1] => 3 ) [67] => Array ( [0] => 2021-06-09 [1] => 0 ) [68] => Array ( [0] => 2021-06-14 [1] => 1 ) [69] => Array ( [0] => 2021-06-16 [1] => 0 ) [70] => Array ( [0] => 2021-06-21 [1] => 0 ) [71] => Array ( [0] => 2021-06-23 [1] => 0 ) [72] => Array ( [0] => 2021-06-28 [1] => 0 ) [73] => Array ( [0] => 2021-06-30 [1] => 0 ) ) And i'm using this code to remove but no success print_r(array_values(array_filter($cronograma)));
Any help please
Thanks Hello, I have two arrays: $questions, which has 'question_id' as one of its keys and $assignment_questions which is a subset of $questions, pulled off my database. Using php, I'd like to construct a 3rd array which takes my $questions array and removes from it any question that has a question_id which can be found in both $questions and $assignment_questions, in addition to the other values associated with a particular question_id. For example, $questions has: question_id, solution, author (and other keys). Is there any way to check if a particular key matches and then zap out all of the corresponding fields (solution, author, etc.)? Thanks! So Im building this little link scraper. The problem I am having is when it outputs the links that are in the array its got duplicate elements. I'm trying to erase the dupes and only show unique values. I've tryed array_unique() with out success as well as in_array(). Any help would be appreciated! //PAGE WE ARE GETTING LINKS ON $diags = str_get_html(getDiagramLinks($html)); //GET THE DIAGRAM LINKS TO PAGES INTO ARRAY foreach($diags->find('a') as $f) { $diagLinks[] = $f->href; } //iterate through the array for($i=0; $i<sizeof($diagLinks); $i++) { //ignore if blank element if(trim($diagLinks[$i]) !== ' ') { echo $diagLinks[$i]. '<br>'; } } The Output: Code: [Select] /partsearch/model.aspx?diagram_id=110375 /partsearch/model.aspx?diagram_id=110375 /partsearch/model.aspx?diagram_id=110376 /partsearch/model.aspx?diagram_id=110376 /partsearch/model.aspx?diagram_id=110377 /partsearch/model.aspx?diagram_id=110377 /partsearch/model.aspx?diagram_id=110378 /partsearch/model.aspx?diagram_id=110378 /partsearch/model.aspx?diagram_id=110379 /partsearch/model.aspx?diagram_id=110379 /partsearch/model.aspx?diagram_id=110380 /partsearch/model.aspx?diagram_id=110380 A problem has arisen which puzzles me. I have forms which save data to MySql and retrieve it, showing it as the default data in the form. Naturally I escape any quotes before sending it to the database and remove the slashes when I retrieve it. But the form HTML code shows the data like this value="$variable" which is fine when only single quotes are used in the data but causes a problem when the user uses double quotes. So data of John \"Jack\" Smith would be output as value="John "Jack" Smith" with obvious problems. If I use value='...' then that would cause problems with single quotes. I haven't seen the answer in any of my books. The only things I can think of is changing all double quotes to single before saving to DB or converting them with htmlspecialcharacters so they are no longer actual quotes. I dont even know where to begin doing this. I am supposed to remove duplicate entries in this 2 dimensional array but I just can't find any answers anywhere. Code: [Select] <?php /* In the following two dimensional array (an array of arrays) you will notice that there are several duplicate entries (David and Patricia). 1) Write a basic function which will go through $input and remove the duplicate entries. A "duplicate" is an entry which has the same FirstName and LastName as another entry. Ignore the other fields. Call your function "dedupe1". It should return a two-dimensional array without these duplicates 2) Using your dedupe1 function, write one called dedupe2 which will detect empty DOB's and DOB's of '00/00/0000'. When an empty or zeroed DOB is detected, your code should use the entry with a complete DOB (if available). Like dedupe1 your code should return a two-dimensional array without duplicates. If you use the provided $input function, all of the returned entries should have a complete DOB listed. */ $input = array( array( 'FirstName' => 'Daniel', 'LastName' => 'Anderson', 'Phone' => '614-123-4568', 'Address' => '123 Main St', 'SSN' => '001-01-0001', 'DOB' => '01/11/1922' ), array( 'FirstName' => 'Aaron', 'LastName' => 'Williams', 'Phone' => '937-321-3993', 'Address' => '933 N Park St', 'SSN' => '992-23-1192', 'DOB' => '04/21/1965' ), array( 'FirstName' => 'David', 'LastName' => 'Taylor', 'Phone' => '223-293-9921', 'Address' => '123 Main St', 'SSN' => '003-19-2992', 'DOB' => '12/14/1995' ), array( 'FirstName' => 'Patricia', 'LastName' => 'Anderson', 'Phone' => '614-123-4568', 'Address' => '123 Main St', 'SSN' => '123-32-3123', 'DOB' => '00/00/0000' ), array( 'FirstName' => 'David', 'LastName' => 'Taylor', 'Phone' => '223-293-9921', 'Address' => '123 Main St', 'SSN' => '003-19-2992', 'DOB' => '' ), array( 'FirstName' => 'Patricia', 'LastName' => 'Anderson', 'Phone' => '614-123-4568', 'Address' => '123 Main St', 'SSN' => '123-32-3123', 'DOB' => '02/22/1957' ), ); // Get results from dedupe1 and print them $result1 = dedupe1($input); var_dump($result1); // Get results from dedupe2 and print them $result2 = dedupe2($input); var_dump($result2); print_r($input);//just to see the information in the web page function dedupe1($in_array) { // your code here } function dedupe2($in_array) { // your code here } ?> Hi I have a multi-dimension session array as per the below: $_SESSION['myarray'][][] If for example there are several elements stored in the array: $_SESSION['myarray'][0][0] = "aaa"; $_SESSION['myarray'][0][1] = "111"; $_SESSION['myarray'][1][0] = "bbb"; $_SESSION['myarray'][1][1] = "222"; $_SESSION['myarray'][2][0] = "ccc"; $_SESSION['myarray'][2][1] = "333"; $_SESSION['myarray'][2][0] = "ddd"; $_SESSION['myarray'][2][1] = "444"; How can i remove one of the above and shunt the other elements up? I have tried using the unset command but this seems to essentailly nullify the desired values where as what i would like to do is remove them completly from the array and then shorten the total number of records stored in the array. Thanks for taking the time to read this. Hi all, I have an array of data. I am looping through this data to generate a CSV file. However, if there are commas in any of the elements then this will throw out the structure of the CSV file. My question is, how do I loop through the array before I use it to strip out any commas and replace with a space? Thanks for your help. |