PHP - Picking Out Number From A Url String?
Hey guys, I have a url that looks like this
http://www.mysite.com/our-company-t-2.html I need to extract the number at the end. It's 2 here but could be 2478 for example. Just wondering how I can do this. Would it need to do something like look for anything between "-" and ".html" ? Similar TutorialsHey I have a string that looks like the following: Quote top-php-tutorials-2.html I have a script that cycles through each page. The 2 in the quote above is the page number. How can I extract the number between the - and the .html and replace it with another number? I've tried Code: [Select] substr($engine->selectedcaturl, 0,-6).$v.".html"But then I realised this only works for numbers that are 1 digit long Any input would be appreciated How can I test if a string has a number at the end? i.e. smith1 instead of smith? I won't know how long the string is or whether there is more than 1 number but I will know that the string's last character is a number. Thank you! I need to find first digit (any number 0 - 9) in a string. I thing I should be able to use: $NumberPosition = strpos($Source, "/[0-9]/", $NumberPosition+1); but it does not work, wonder what I am doing wrong? I can't figure out how to pull the number from a form name Unfortunately I cant use substr(); because non of the names are the same length... these are the form names cat_sub_id_1 cat_name_1 cat_order_1 cat_sub_id_2 cat_name_2 cat_order_2 cat_sub_id_3 cat_name_3 cat_order_3 this is a list of the numbers that I need to be pulled out. I have a really weird thing that I have to do, and I can't figure it out. I've tried about 1 million nested loops, and just can't get this to work. What I need to do is get the longest number from a string. So, for example, take the following: $string = "asdfasd234kjljlkjlj34659823423sadfasdadasdfasdfas d3242sdasddsda2"; function getNumber($a) { //do something with $string and return the longest number from it } so that ... echo getNumber($string); will return '34659823423' Thanks in advance, fellas! I've really been racking my brain there. Hello, I'm working on an error form, and I want to check if the user inserted a number into the name field, and if so return an error. I thought this might of worked, but it doesn't: Code: [Select] if(is_int($_POST['name'])){ $arrErrors['name'] = 'Invalid name, remove numbers.'; } Many thanks I have a large amount of text, (text can be different at any time), I count the number of characters in the string,and divide it by 2 so that half of the text will be in one variable, the other half in the other, however I am not sure how to get the split function, or whichever function to split it by the number of characters. example: $text = "lorem ispum dolar sit amet, consecterur adiscing elit. Donec dictum placerat sapien, in eliefend liber"; $cut = strlen($text)/2; //(here's where i cannot get it to work/do not know which function to use and how to use it) //but what I want it to do is to split it half way. I was wondering if anyone knows a good way to check for an even number of each character in a string. For example if the string is "abbacc" then it will return true as there are two of each character. However if the string is "ababc" it will return false as there is only 1 c. Thanks for any help String: NodeJs is one of the best technology Quote
NodeJs is one of the best technology
How to print the largest even number? I've got a string which is usually abc-def-0123 but it sometimes has an additional dash and then a single digit (e.g. ghi-jkl-4567-1). It's always the same pattern and length, (three letters, a dash, three letters, a dash, 4 digits then the possibility of a dash followed by a single digit). What's the best way to test if the string ends in a dash followed by a single digit? Any help much appreciated! I have a string in the form of "word1-word2-word3-word4-word5-word-6-word7", but I want to shorten it to 5 words only. How could I split a string in half but not in the middle of a word? $information = "This is the string of text, however at some point in the sentence a word may get split in half."; $cut = round(strlen($information)/2); ///where to cut (50%) $split1 = substr($information, 0, $cut); //first half $split2 = substr($information, $cut); // second half This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=353613.0
Hi all dear
<!DOCTYPE html> <html> <body> <?php function generatePermutation($string,$start,$end){ if($start == $end-1){ echo "$string - "; } else{ for($i = $start; $i < $end; $i++){ $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; generatePermutation($string,$start+1,$end); $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; } } } $str = "ABC"; $n = strlen($str); echo "All the permutations of the string a "; generatePermutation($str,0,$n); ?> </body> </html>
I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Using phpMyAdmin I loaded 6 test records with the id set to auto_increment and it loaded all the data correctly with id # 1-6. Then from somewhere it got the number 333353 and auto_increments it as the value for the id. So now I have id's 1-6 and 333353, 333354, ect. For every record I add it increments it. I deleted all but records 1-6 and tried again but it has the last value of 3333xx stored somewhere and increments it. Deleted them again, closed the program, came back and it still does it. Hiya guys, I'm having problems with a code i have written, it seems that nor google or my own search engine is picking up the links? And i don't understand why. I know the following code has a div on click rule, but i have also added an a href. I tried the basic link which is also not picking up. Code: [Select] <?php $old_pattern = array("/[^a-zA-Z0-9]/", "/_+/", "/_$/"); $new_pattern = array("_", "_", ""); $i = '1'; while($row = mysql_fetch_array($result)) { ${videoData_.$i} = mysql_query("SELECT * FROM videoData WHERE qid=".$row['id']."") or die(mysql_error()); ${row_.$i} = mysql_fetch_array(${videoData_.$i}); ${vote_.$i} = mysql_query("SELECT SUM(votes) FROM answers WHERE qid=".$row['id']."")or die(mysql_error()); ${votes_.$i} = mysql_fetch_array(${vote_.$i}); $pagelink = strtolower(preg_replace($old_pattern, $new_pattern , $row['question'])); echo '<div class="NVP-div" '; echo 'onclick="location.href=\'http://www.thevideopoll.com/polls/'; echo $link = "".$row['id']."-_-".$pagelink.".php"; echo '\';" style="cursor: pointer;"'; echo '>'; echo '<img style="float:left; margin-left:25px;" src="http://img.youtube.com/vi/'.${row_.$i}['videoID'].'/default.jpg">'; echo '<p class="NVP-vote">'; echo ${votes_.$i}['SUM(votes)']; echo ' Votes'; echo '</p>'; echo '<br>'; echo '<a class="new-video-links" href="http://www.thevideopoll.com/polls/'; echo $link = "".$row['id']."-_-".$pagelink.".php"; echo '" title="'.$row['question'].'">'; echo "".$row['question'].""; echo "</a>"; echo '</div>'; $i++; } ?>
I have 3 staff members that need to pick vacation in a certain order.
~~~~~~First round of picking~~~~~~
Staff 1 takes 2 Weeks
~~~~~~Second round of picking~~~~~~
Staff 1 takes 1 Weeks
~~~~~~Third round of picking~~~~~~
Staff 1 Skipped
~~~~~~~~~~~~ --calendar.php-- $year=2020; $sql = "SELECT * FROM vac_admin WHERE pick_year='$year'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row_admin = mysqli_fetch_assoc($result); } $current_pick_staff = $row_admin['current_pick_staff']; $sql = "SELECT * FROM vac_pick_order WHERE pick_year='$year' && pick_order = '$current_pick_staff'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if($row['vac_c_counter'] < 0){ $emp_num = $row['emp_num']; }ELSE{ ?????????????????? goto next staff with weeks > 0 ?????Somthing like if ($current_pick_staff == 3){ $current_pick_staff = 1; }ELSE{ $current_pick_staff++; } ?????????????????? } ~<FORM>~~~~~~~~~~~~~~~~~~~~~ Staff with $emp_num can now pick ~~~~~~ $_POST -> $date = XXXX-XX-XX; $num_weeks = X; $emp_num; ~</FORM>~~~~~~~~~~~~~~~~~~~~~ --process.php-- $year = 2020; $date = $_POST['date']; $num_weeks = $_POST['num_weeks']; $emp_num = $_POST['emp_num']; $sql = "INSERT INTO vac_picks (pick_year,emp_num,date) VALUES ($year,$emp_num,$date)"; $sql = "UPDATE vac_pick_order SET vac_c_counter=vac_c_counter - $num_weeks WHERE emp_num='$emp_num'; $sql = "UPDATE vac_admin SET pick_order=pick_order +1 WHERE pick_year='$year' ; Then back to calendar.php until all weeks gone.
Hi good people, i'm vary new in this and i'm having trouble with PHP while writing some project for school and because i find many answers on this forum till now i decide to post this.. so here is my problem: I'm trying to make a web page for students and profesors where students (when they are loged in) will be able to sign a date for their exam so i made a form like this : Code: [Select] <form method="POST" action=""> choose exam: <p><select name="exams"> <option value="k1D">exam 1</option> <option value="k2D">exam 2</option> <option value="k3D">exam 3</option> </select></p> choose date: <p><select name="dates"> <optgroup label="Zimski rokovi"> <option value="2011-02-01">01.02.2011.</option> <option value="2011-02-07">07.02.2011.</option> <option value="2011-02-15">15.02.2011 </option> <optgroup label="Ljetni rokovi"> <option value="2011-05-21">21.05.2011.</option> <option value="2011-05-28">28.05.2011.</option> <option value="2011-06-04">04.06.2011.</option> </select></p> <input type="submit" value="Prijavi ispit" name="prijavi"> </form> table for students in mysql has columns for every exam (k1D , k2D..) but how can i make so that student can pick wich exam he wants to sign on some of dates (wich column he wants to fill with wich of dates) ? i tryed some variations of : Code: [Select] $k1D = $_POST['dates']; $kol = $_POST['exams']; mysql_query(" UPDATE studenti SET '$kol' = '$k1D' WHERE ID = '3'"); but i'm just getting different errors.. Hi guys, For a project I made sort of a custom cron database. Database has 4 columns: ID (auto increment), TaskID, DateTime, Locked. I'm running a 1 minute cron in the form of a php script. The script itself starts with a query that loads a task with 'Locked != 'Y' and DateTime < NOW( ). It then locks the task (by flagging the 'Locked' field in the db) and launches another script that finishes it. That last script deletes the task when finished from the cron database. Problem is, at certain peek hours, the system would get laggy, there'd be a bunch of tasks stacking up and it would get behind on the schedule. In order to combat that, I made an extra 1 minute cron, launching the same script. Now, my problem: mysql is too slow In principle, there shouldn't be any problem: all tasks picked up by either instance of the script would be locked so the other instance wouldn't be able to pick up the same task. The problem occurs when both instances are booted at the same time (well, one after the other but with a minuscule time difference between them) and they both at the same time run the query to get a 'free' task from the database: the system will give them both the same task before either of the script instances has the time to lock it up. I'm trying to think of some solutions but I'd like your feedback on what solution would be best. - Putting an exclusive lock on the php file is not an option for me since I still want to run the script, I just need it to pick up an exclusive task. - Other option: having the script open with a random sleep of (1, 10) seconds, it will have the script instances pick up a task at a different time, giving the other instance time to lock it up. Obvious disadvantage: I'm losing time. - Using a file as a flag. Set a directory and create a file in it. Check if this is the only file in the dir, if yes: start right away. Otherwise: go to sleep for 2 seconds (should be plenty of time to run 2 queries in the other instance). What is the fastest method of doing a directory scan though, glob()? My question: what's the fastest/best way to solve this? Thanks! |