PHP - Noobie Preg_match Question
Why oh why does this not work?
<?php
if (preg_match("[0-9]", "2")) {
Similar TutorialsI have a script that uploads pictures to a folder. I used mkdir to create this folder and sub folders. Do I need to chmod folders and files, do i need to do this to my other html, php and image files. I am completetly confused who is the owners group etc thanks I have this $val="my friend is a female"; how to check whether a word "male" is there or not using preg_match() i wish to get FALSE result for that case and TRUE if i modify a bit into $val="both male/female" thanks in advance! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=357263.0 I have searched a lot but no information about this aspect. I wonder how much heavy is the process of getting parts of a webpage by preg_match? But my question is that which of these options are in favor of lighter CPU process: 1. getting each item between specified tags by a preg_match or 2. First getting the content between <body>, then processing by php tools such as preg_match (again), explode, etc. Thanks for considering this unusual question Hi, I'm using preg_match to validate various fields. I wish to check that a string the length of four numbers, as a year, eg. 2010. How would I do this, something like: Code: [Select] /^[0-9'\s]{4}*$/i? As usual, I have no idea. Hi all i bet this is going to be obvious, but I ran out of ideas. I have the following script but it's not inserting. I gave the user database specific insert update and select rights but something is not working. maybe someone could help me out. $dbc = mysqli_connect('localhost','slave','password','mydatabase') or die ('error connecting to mysql server'); //display stuff $query = "SELECT * FROM mydatabase"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo 'id: '.$row['ID']. ' and firstname is: '.$row['firstname']. ' and lastname is: '.$row['lastname'].'<br />'; } //insert stuff $query = "INSERT INTO `mydatabase`.`users` (`firstname`, `lastname`) VALUES ('john', 'doe')"; $result = mysqli_query($dbc, $query); mysqli_close($dbc); -edit ok i think i fixed it, i tried the root user and it worked. gave the slave user more rights. apperently besides database specific i ahve to give the slave user global insert update and select rights too. Can someone confirm that? Hi, I'm a learning PHP developer, and I'm trying to work out how to connect and use an API provided by my goverment to the public. I have no idea how to set it up and test it, and I'm having a really hard time finding any help online.
The documentation mentions using a "simple" cURL request but I have no idea how that works either, and I would like ideally to be able to pull the data and turn into an SQL database where I know how things work a little bit better within PHP.
Many thankss Hi im trying to do a registration form and i am new to using preg_match. I keep getting the error "( ! ) Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\wamp\www\registration1.php on line 67" and for every other line I use preg_match. this is an example of how i have used it Code: [Select] if ( preg_match('^[[:alnum:]\.\'\-]{4,50}$', stripslashes(trim($_POST['UserName']))) ) { $UserName = mysql_real_escape_string($_POST['UserName']); $query = "SELECT UserName FROM Users WHERE UserName = '$UserName'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); im such a noob at this can someone please help me I would also like to add that I have read the http://www.php.net/manual/en/function.preg-match.php page but i dont really understand it. Hi, I have the following code which FTPs to a site, gets the source code for a HTML file and then puts the data inbetween <TITLE> and </TITLE> into an array and this works fine: <?php $file = file_get_contents("ftp://user:pass@domain/public_html/index.html", "r"); if (!$file) { echo "<p>Unable to open remote file.\n"; exit; } preg_match_all ('/<TITLE>(.*)<\/TITLE>/msU', $file, $matches, PREG_SET_ORDER); print_r ($matches); ?> Rather than finding a match for data between <TITLE> and </TITLE> however I would like it to pull back what is inbetween the following: <!--START--> and <!--END--> I have tried the following but it doesn't put anything into the array: preg_match_all ('/<!--START-->(.*)<\/!--END-->/msU', $file, $matches, PREG_SET_ORDER); This is the content of the html file if this helps: Code: [Select] <TITLE>The Title</TITLE> <!--START--><p><strong>Some Text</strong></p> <p><strong><img src="images/IMAG0152_2.jpg" alt="" width="200" height="100" /></strong></p> <!--END--> i can get a match on stuff between TITLEs but not START and END.. I'm not sure how to change preg_match_all to work!! i've tried loads of combinations but can't get any to work, but i'm not really sure on modifiers and patterns or escaping etc, if anyone could help that would be great. Thanks in advance kev. im trying to make a script so i can get users details like longitude, latitude etc
but im having trouble matching the html by regular expression
here is the html below that im trying to extract the data from:
any help or possible any alternative, suggested ways would be greatful thank you
<td>Country:</td> <td><img src="/images/dot.gif" class="flag-16 gb" align="absmiddle" width="16" height="16" title="United Kingdom"> United Kingdom (GB)</td> </tr> <tr> <td>City:</td> <td>Newport</td> </tr> <tr> <td>Region:</td> <td>Newport</td> </tr> <tr> <td>Latitude:</td> <td>51.5833</td> </tr> <tr> <td>Longitude:</td> <td>-2.9833</td> </tr> <tr> <td>Timezone:</td> <td>Europe/London</td> <?php $url = "http://smart-ip.net/geoip/2.101.108.124/"; $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); if (preg_match('/<td>Country:</td><td>[img](?P<country>\w+)</td>/$', $rawdata, $match)) { $country = $match['country']; } if (preg_match('/<td>City:</td><td>(?P<city>\w+)</td>/$', $rawdata, $match)) { $city = $match['city']; } if (preg_match('/<td>Region:</td><td>(?P<region>\w+)</td>/$', $rawdata, $match)) { $region = $match['region']; } if (preg_match('/<td>Latitude:</td><td>(?P<latitude>\d+)</td>/$', $rawdata, $match)) { $latitude = $match['latitude']; } if (preg_match('/<td>Longitude:</td><td>(?P<longitude>\d+)</td>/$', $rawdata, $match)) { $longitude = $match['longitude']; } if (preg_match('/<td>Timezone:</td><td>(?P<timezone>\w+)</td>/$', $rawdata, $match)) { $timezone = $match['timezone']; } ?> I have a DOMDocument which I inspect an HTML page for links (href) That part works however I am not sure how to use preg_match if I only want to display a link in this layout: <tr> <td headers="c1"><a title="Link to entity information." tabindex="1" href="CORPSEARCH.ENTITY_INFORMATION?p_nameid=3236937&p_corpid=3227476&p_entity_name=%41%72%77%65%6E%20%45%71%75%69%74%69%65%73&p_name_type=%41&p_search_type=%42%45%47%49%4E%53&p_srch_results_page=0">ABC LLC</a></td> </tr> I hope someone is really good at preg_match to help me. Thanks. I need to select an array item based on my preg result. for example: Code: [Select] $content = 'test-1'; $match = preg_replace('|test-([0-9])|', $array['\\1'], $content); is this possible? I've tried alot of different ways, google, but just can't find the correct way to do this.. I'm trying to search for a word in an inputted string.. here's the code <html> <head><title>TESTING</title></head> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"/> email: <input type=text name=email value="" /><br/> feedback: <input type=text name=ex value=""/><br/> <input type="submit" value="submit" /><br/> </body> </html> <?php $email = $_GET['email']; $ex = $_GET['ex']; $pattern = '/^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z]+$/'; //$pattern1 = '/nprezident/prezident/'; if(!preg_match($pattern, $email)){ echo 'invalid email address<br/>'; } else { echo 'good to go<br/>'; } if(preg_match('/nprezident/,/prezident/', $ex)){ echo 'just something about that sentence is nice'; } else { echo 'no good'; } ?> Ok the one I'm having a problem with is the second preg_match when trying to search for two words i can get one word to print but when i use add a second word it gives an error. How do i add a second word? Hi,
I have a "scraped" string and want to use the preg_match() to give me just a pice of it.
The string is from a webpage, but is dynamic....
here´s the typical string format:
<a class="stripped-link lightblue-link profile-page-link" href="/x/xxx+xxx+xxx/xxxx">HER IS THE WANTED TEXT</a>
The orange is static. The green (the xxxx is the dynamic part of the string)
Can I use the preg_match() for this?
thanks (and yes I´m a newbe.... )
in my site search some of the results come out still with html. i have used the strip tags function but how would i use the preg_match function to get rid of the "> still left over? Why dosent this work, im trying to match upper case, lower case and numbers only Code: [Select] $id = '3xDJ7@#'; if (!preg_match('/^[a-zA-Z0-9]/', $id)){ echo "ERROR!"; }else{ echo 'ok'; } This always echos "ok" information.txt <li><img src="http://www.lol.com" alt="0" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="4" /></li> <li><img src="http://www.lol.com" alt="9" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="7" /></li> <li><img src="http://www.lol.com" alt="2" /></li> How can I get the alt="$ValueIwant" for each with a preg_match Im trying to match this string, but i dont wat to match normal words like "hello world 646" Code: [Select] $string = "2ab055843241f20044af82ae0d5ace04"; //always over 15 chars - without spaces if ( preg_match('~^[0-9\s]+$~D', $string)) { echo 'yes'; } If i can do it with preg_match that would be great I'm pretty new to this, How exactly could i get the text between the www. and .com? so if i have a url: http://www.facebook.com I want to just return "facebook" Hi,
I don't know much about php. Recently my host updated php version to 5.4 and i function eregi() is deprecated errors, so after some googling, replaced it with preg_match but i am stuck with errors
Code:
preg_match("^ and", "", $mid_str)
Error: Warning: preg_match(): No ending delimiter '^' found
Tried the following method but not working
preg_match("/^ and/", "", $mid_str)
Can you guys help me with correct code?
Thanks for looking.
|