PHP - Parsing Url For Certain Strings
Hey guys!! So basically what I am doing here is pulling the directory out of a url.
URL ex: http://www.xxx.com/T...IS_WHAT_I_WANT/ Similar TutorialsNot sure if there is a better way to do this, but I want to check whether the value in a Sticky Field is the same as what is in the Database. If what is in the Sticky Field is *exactly* what is in the Database, then the User didn't update that field, and so I would NOT do an UPDATE. Seem reasonable? Here is where I grab the value out of the Form... Code: [Select] // **************************** // Process Each Form Field. * // **************************** foreach($_POST['answerArray'] as $questionID => $response){ // Copy trimmed Form array to PHP array. $answerArray[$questionID] = trim($response); And here is where I grab the existing value in the Database... Code: [Select] // ******************** // Check for Answer. * // ******************** // Build query. $q1 = "SELECT response FROM bio_answer WHERE member_id=? AND question_id=?"; // Prepare statement. $stmt1 = mysqli_prepare($dbc, $q1); // Bind variable to query. mysqli_stmt_bind_param($stmt1, 'ii', $memberID, $questionID); // Execute query. mysqli_stmt_execute($stmt1); // Store results. mysqli_stmt_store_result($stmt1); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt1)==1){ // Answer Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt1, $currResponse); // Fetch record. mysqli_stmt_fetch($stmt1); So I guess I want to compare $answerArray[$questionID] against $currResponse and see if there are any differences?! What is the best way to do that? Any better ideas of how to check to see if the User made any changes to a field so I only do an UPDATE if there was actually a change? Thanks, Debbie is there a way I can make something like a ticket in pdf format that can have $name or the likes echo in it? if you could help get me started, that would be great! Hello, I was wondering if someone could help me to "get" the webaddress of a current webpage and then pull off pieces of the page. All of my pages look like: http://localhost:8888/algebra_book/Chapters/Quadratic_Functions/introductory_problem.php BUT, the stuff to the left of Quadratic Functions WILL change in the future. So all will look like: *Quadratic_Functions/introductory_problem.php Then, I'd like to pull off a $chapter variable, which in this case is Quadratic_Functions and a $page_name variable which in this case will be introductory_problem. Thanks so much. How can i break down strings for example i have a simple search database for products where as a user searches a term this can be one, two three words and so on. I'm using a wildcard; but i want the best way to get the possible search so i would like to break down the string into separate words and then use that to search the database using wildcards is this possible? Thanks for reading. hello, here is what i have, obviosly it doesnt work. Code: [Select] $year=$_POST['y']; $yr=substr($year,-2); $mth=$_POST['m']; $init=$_POST['initial']; $jobnumber=$yr$mth2343$init; echo "$jobnumber"; P.S. thanks to everybody for their help lately! I was thinking how can I make a script that will build strings incrementing through each letter starting with "a" and ending with "zzzzzz" or what ever ending length I want such as 12. So if your were to output everything, you could find the words: "dog" "spider" "superman" "hippo" etc What would be the best way to do this, so I don't have to have a loop that is 500 blocks deep to show a word that is 500 letters example Quote a ... z aa ab ac ... az ba bb bc ... ... aaa aab aac Hi I am having troubles using a string in a cookie.. This doesnt work: setcookie("background", "$image_name", $expire, "/", ".gedoo.com"); Neither does this: setcookie("background", "" . $image_name . "", $expire, "/", ".gedoo.com"); If I write something before $image_name like: setcookie("background", "hello" . $image_name . "", $expire, "/", ".gedoo.com"); It will save "hello" in the cookie.. So in other words, $image_name doesnt look like it is defined.. But the funny thing is that this works on the same page: echo "File Uploaded Successfully!<br><img src='images/$image_name'>"; Anyone have any idea on what I am doing wrong? Hey guys, I have used this code before on a linux server and know that it works, however after porting my site over to a windows server running apache, php and mysql; the following code seems to make one of my scripts crash. $queryfam1 = "SELECT * FROM wp_users WHERE user_login='$username'"; $resultfam1 = mysql_query($queryfam1) or die(mysql_error()); $row21 = mysql_fetch_array($resultfam1) or die(mysql_error()); I have no idea of a result as there is no error reported, it simply dies and does not tell me what is happening with it. Any ideas? Hey Im trying to extract urls from inputted data so i can seperate it from the rest of the text but can't seem to work out what regex i need to use. The main issue is im trying to extract a specific domain example (google.com) But it could be written 4 ways (google.com, http://google.com, http://www.google.com, www.google.com). Does any one know how you do it ? Hello guys, need some help. Let us say i have an array = 2011 ipad 2011 ipad review 2011 ipad price 2011 ipad design 2011 ipad reviews review 2011 ipad 2011 ipad feature I would like to review all the array elements that contain "review"...So the final array should look like 2011 ipad 2011 ipad price 2011 ipad design 2011 ipad feature Thanks Hmm, not quite sure how to do this one... If i have lots of strings saved in a mysql table and one was... "A man and a dog took a nice walk in the park" If a user then wanted to input another string into the table, but i wanted to check the new string was at least 5% different to all other in the table, how would i about doing this? Is it possible to do this via mysql, or would i have to pull out all the strings into a php array and process it that way... somehow? I can successfully concatenate strings and vars to assemble a php var using an echo statement like this: Code: [Select] echo "<input type='radio' id='radio_btn_" . $Row['question_number'] . "_0' name='question[question_" . $Row['question_number'] . "]' value='0' checked='checked' />"; However, when attempting to reference the same var in an IF statement, I can't seem to get the syntax right. I know this syntax is wrong, but I list it for reference to describe the issue I am trying to solve. Code: [Select] if ($_POST['radio_btn_' . $Row['question_number'] . '_0'] == '0'){ I also tried curly braces but can't arrive at a solution. Any advise would be appreciated. Hello, I'm working on a script for my chat software that will convert an array into a string and then can easily later on be put back into an array, I've already done this but when I did it I didn't think of sub-arrays. For example of an array: Code: [Select] $user_info = array( 'username' => 'test', 'other_info' => array( 'var' => 'value', 'var2' => 'value2' ) ); and that would change into something like this: user_info:{username:test, other_info:{var:value,var2:value2}} I do not care what the string looks like, above was just an example, any separators can be used. I just can't have it messed up by user input (a username with a character of a separator or something). The code I have works for this: Code: [Select] $user_info = array('id' => 1, 'username' => 2); and it outputs this as the string id=1&username=2& The code I use is: Code: [Select] function strtoarray($str) { $info = explode("&", $str); if (is_array($info)) foreach ($info as $data) { $data = explode("=", $data); if (is_array($data)) { if (!empty($data[0])) { if ($array[$data[0]]) { if (!is_array($array[$data[0]])) { $array[$data[0]] = array($array[$data[0]]); } $array[$data[0]][] = stripslashes(urldecode($data[1])); } else { $array[$data[0]] = stripslashes(urldecode($data[1])); } } } } return $array; } function arraytostr($array) { foreach ($array as $key => $value) { $str .= $key . "=" . addslashes(urlencode($value)) . "&"; } return $str; } I'm really not sure if regex is the way to go with this or what and that's really why I'm asking for help. I know I could do this with more explodes and what not but I feel as if there's probably a better way to do this and I'm just over complicating it. Thank you in advance. I am trying to make a little script that allows a user to search for blocks of text within strings. The user enters data into form fields and he or she can enter text into another form field (needle) to search the data fields (haystack). When the search string matches something in the data fields the associated data fields are highlighted in a yellow background color. Right now the search string is acting funny. When I enter a search string I get no highlighting unless if the first character(s) of the search string are the same as the first character(s) for the items. For instance, If I search for the text "at" in the word "bat" I will not get any yellow highlighting. But I would get highlighting for "bat" if I search for "ba." How would I change the code so that any data field is highlighted if the search string exists anywhere in the text for the data field? Also, I figured out how to stop the form fields from being yellow if they and the search field are empty/NULL, but I did this part in another file (as an IF statement) and can't seem to get it to work in the other file. How would I make it do the highlighting if and only if there is a search string in the search field (i. e. only highlighting when the search field is not NULL/empty). The code from my 2 files is here...: http://pastie.org/1095526 , http://pastie.org/1095528 Thanks very much to anyone who can help me. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=316055.0 Good day all.
I am trying to get strings from txt file with a start and an end.
$file = "/var/www/html/sataxicrm/custom/include/language/lang.en_us.lists.php"; $content = file_get_contents($file); $pos = strpos($content,"query_complaint_type_list"); $end = strpos($content,"status_0"); $string = substr($content,$pos,($end- $pos)); $array = nl2br($string); //print $content; echo "Database Value:Label Value <br>"; print $array;
The above code works well if you knowwhat your end string is, but in my case i do not know. i only know the start. As you can see i know it starts with account_type_dom but i do not know that it will end before industry_dom. so i need to stop before industry_dom. how do i do this? Quote
account_type_dom
This is the full error: Fatal error: [] operator not supported for strings in D:\Programs\AppServ\www\test\test.php on line 19 I have comented on the error line. function structure(){ $argNum = func_get_args(); $temp = $argNum; (int)$pointer = -1; $xmlStructure = array(); foreach ($temp as $key => $value) { if ($value == 'in') { if ($pointer == -1) { $pointer = 0; } else{ $pointer = $pointer + 1; } }elseif ($value == 'out') { $pointer = $pointer - 1; }; if($pointer != -1){ $xmlStructure[$pointer][] = $value; //THIS is the 19'th line. }else{ $xmlStructure[] = $value; } } return $xmlStructure; } function test_print($item2, $key) { echo "$key. $item2<br />\n"; } $a = structure('0','in','00','01','02'); array_walk($a,'test_print'); I've got a file with some strings that have both types of quotes in them. And I seem to have managed to get the data, display it in my html, store it in a js array (using a json_encode in php and then simply inserting it into my js) but I cannot seem to pass the string as a parameter form an onclick function call to js.
For most strings the addslashes makes it work in the function call. But for those with both sets of quotes it won't work. My console tells me there are "unterminated string constants..". I've experimented with many silly changes but none make it work.
Ex. of the strings:
What do you mean "It's crooked"?
Of course I could remove the contraction and that would probably work, but that would be a hack, would not it?
I have a php page which is ran after a form is posted from the previous page. I am having trouble getting the SQL strings to work. When the page is ran online there is no WSOD or error message but the tables in my database are not being updated. Any help with this would be greatly appreciated.
Attached Files
payment.php 1.79KB
4 downloads |