PHP - How To Make Preg_match Match Entire Number?
This is my preg_match code:
preg_match("/(\d+)|(T)|(A)/", $link, $matches, PREG_OFFSET_CAPTURE, ($off-30)
It works and matches the number I want, except it only returns the first character in the $matches array. For instance, if the number it finds is 10, it only returns 1. Now I understand that is what preg_match does, but how would I make that regex ungreedy? I tried adding a *, but it just made an error, and preg match all would keep searching for strings after the first one. All I want is for the first number, regardless of the length of it, to be returned in full. Thanks for any help.
Similar TutorialsI'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? Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. Hi i want to match $ symbol from the string. I am using the following script Code: [Select] $str="ckj"; if(preg_match("/^$/",$str)) { echo "Dollar is found"; } else { echo "Not Found"; } Its not working fine. Can anyone help me out please. I am using preg_match() to perform a url regular expression match for a video embed function.
I have provided the third parameter of preg_match ($matches) therefore $matches[0] should contain the text that matched the full pattern, however I have noticed in the code example below, that the space after the query component of the specified url together with the first word after the space is captured and stored in $matches[0] as well.
$UserInput = "This is my video embed, http://www.youtube.com/watch?v=GXHijTS9_2g check it out ."; preg_match('@http:\/\/(?:www.)?(\w*).com\/watch\?v=(\w*\W?\w*)@', $UserInput, $matches);var_dump($matches) provides the output below: array (size=4) 0 => string 'http://www.youtube.com/watch?v=GXHijTS9_2g check' (length=48) 1 => string '' (length=0) 2 => string 'youtube' (length=7) 3 => string 'GXHijTS9_2g check' (length=17)What am I missing in the regex? Thanks. Edited by terungwa, 23 August 2014 - 05:41 AM. Please help me with this code. It keep appear in my website. "Warning: preg_match() [function.preg-match]: No ending delimiter '.' found in /home/kengsite/public_html/wp-content/plugins/statpress/statpress.php on line 1184" And this is how the line look like. if (!preg_match(".ico$", $urlRequested)) { return ''; } Hi All, I am trying to create a PHP code that will run a form, however i keep getting the error message Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in D:\xampp\htdocs\HFCC\Scripts\mailprocess.php on line 55 Invalid email address entered. Go Back and try again attached is the complete copy of the code i am using, i have an email text box and label with the id 'email' also my method is POST and my action is Scripts/mailprocess.php. Please let me know if you need any additional details. Any help will be much appreciated. Thanks I want to validate a form field for a number with two decimals (ie. 894567.29), but my script gives me an error, asking me to correct the entry, Following is a snippet of the script:- elseif($field == "oil_waste_ltr") { if(!preg_match("/^[0-9]{1,10}\.{2}$/",$value) ) { $bad_format[] = $field; } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345873.0 Hi All, Sometimes after some calculation php may return this: 1.02563125481E+54 But how to make this into 1 number without the E+ etc ?! Cheers hello, if i have $big=3410 how can i take the last 2 digits of that to make it so that i only get the 10? hope this makes sence. <ul> <!-- List the rest of the articles found in the category --> <?php else : ?> <li class="otherrecentmain"><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"></span> </li> <?php endif; ?> <?php endwhile; ?> <!-- END --> </ul> For some reason, its stuck on displaying 9 articles but I want to be able to control how many I want. I may want to choose 17 or whatever etc, not sure how to add it into the php. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> What I'm trying to do is get my $_SESSION to work throughout my website.
I'm quite new to PHP, so the PHP Manual didn't make much sense to me, so I thought I'd post here! ^^
I've got my login script under /session/ and I want it to be able to display your username on the homepage (/), but it only works inside /session/.
If you are wondering, I am using PHP-Login Advanced.
Thank you,
- Connor!
Edited by ConnorMcF, 26 January 2015 - 04:45 PM. I have an array containing webpages. $results = array(www.google.com, www.phpfreaks.com); echo file_get_contents($results[0]); echo file_get_contents($results[1]); Is there anyway to just echo get_file_contents without putting in the position in the array as I have hundreds of variables in it? Hello everyone, I have a general question about something that I've been thinking about doing but have not tried yet. It involves including entire php pages rather than a short snippet of code. Here's my situation: I've created a website that caters to many different schools, each of which is assigned a sub-domain so that they have "their own" web site instead of going to one site and then clicking a link to get to their page. Every site is identical with the exception of a few images. The way I'm currently doing things is to upload every page of code into each folder the each website. Doing it this way, I'm using a lot of disk space and each time I edit one page of code, I have to upload that page to every folder in my directory. It's not too bad with only a few folders, but as more schools use my site, it could become a nightmare! What I'm thinking about doing is to upload all my pages to the parent directory, then on each page in my folders for the sub-domains just include the corresponding page in the parent directory. I will just keep the images for each sub-domain in the corresponding folder. For example, the actual code for the index page in each of my sub-domain folders would be this: Code: [Select] <?php include("../indexpage.inc.php"); ?> This way, I use less disk space and if I need to edit some code, I do it once, and upload it once to the parent directory, instead of having to upload it to each and every folder. Does anyone see any problem with doing this? Thanks for your opinion. I'm trying to find a way to back up an entire servers file through PHP. I have a script that can take selected files into a zip file but I'm not sure how to make sure that when I loop through directory and files that I get every single file. I was thinking of just foreach(glob('*') as $file up to 10 times but I'm hoping there's something more definite then that method... Thanks When i pass entire url in a get variable as http://www.example.com/index.php?url=http://www.yahoo.com/ I am getting the following error Forbidden You don't have permission to access /index.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. But there is no problem when i use the following http://www.example.com/index.php?url=www.yahoo.com/ http://www.example.com/index.php?url=yahoo.com/ http://www.example.com/index.php?url=yahoo&value=1 I am getting "Forbidden-error" only when i include "http://"(even if it is urlencoded) in get variables. Can any one help me... Is it possible to extract all links from a website (not a single webpage) by php? I am asking about the general idea, as I wish to customize: e.g. from a specified directory and certain domains only. Thanks Hello again, I'm trying to scrape a table from another website using preg_match, especifically, using this code: Code: [Select] <?php $data = file_get_contents('http://tvcountdown.com/index.php'); $regex = '/[color=red]<table class="episode_list_table">[/color] (.+?) [color=red]</table>[/color]/'; preg_match($regex,$data,$match); var_dump($match); echo $match[0]; ?> Heres the thing. It doesnt work I think it's because the first and second anchors are html tags, 'cause if I parse some other stuff without any tag, there's no problemo. Any hints, mates? Thanks This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=320065.0 |