preg-match

PHP url validation + detection

So here is what I need to do. If an user enters this: http://site.com I need to remove http:// so the string will be site.com , if an user enters http://www.site.com I need to remove http://www. or if the user enters www.site.com I need to remove www. or he can also enter site.com it will be good as well. I have a function here, but do...

php regex for checking a string

I need a regular expression for checking a string, that it has more than 2 symbols length, first symbol should be Alphabetic, last symbol should be '_'. And how can I uppercase only first symbol? Thank you. ...

How to write a preg_match_all just for grabbing one specific element ?

Hello, Until the website give me an access to his API, i need to display only 2 things from this website : What i want to grab // Example on a live page Those 2 things are contained in a div : <div style="float: right; margin: 10px;"> here what i want to display on my website </div> The problem is that i found an example on stack...

php preg_replace Check if second capture group contains data

Hi everyone, Here's my code $string = preg_replace("/rad\:([0-9]+)px\;\s+\/\*\sALT\[(.+)\*\/|rad\:([0-9]+)px\;/",("$2"?"$2":"$1"),$string); Basically, in the regex I've got a pipe |, and I'm searching for two patterns. If there is a match to the first pattern (to the left of the pipe), then I want the it to be replaced with the seco...

Preg_match for a date

Hello everyone, I am trying to match a date in PHP using preg_match, split it and assign parts of it to an array, the date looks like "20100930", here is the code I am using: // Make the tor_from date look nicer $nice_from = $_POST['tor_from']; $matches = array(); $ideal_from = ''; preg_match('/\d{4}\\d{2}\\d{2}\/', $nice_from, $matc...

My PHP preg_match expression isn't working.

I tried to directly convert an "eregi" expression to a "preg_match" expression. $ACCEPT_CHARS = "a-z0-9_~#&;=./?+-"; $msg = preg_match("/ (http|https|ftp|gopher|news)://([$ACCEPT_CHARS]+)/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>", $msg); However, I get: Warning: preg_match() [function.preg-match]: Unknown modifier '...

PHP's `preg_match_all` functionality in Java

In PHP if we need to match a something like, ["one","two","three"], we could use the following regular expression with preg_match. $pattern = "/\[\"(\w+)\",\"(\w+)\",\"(\w+)\"\]/" By using the parenthesis we are also able to extract the words one, two and three. I am aware of the Matcher object in Java, but am unable to get similar fu...

How to do a preg_match in php?

Hi I have this argument in php and i want this to just allow users to enter a domain name...i want it so that it doesnt allow characters like "/" "?" and so on...so i only get the domain name such as "http://somedomain.co.nz" or "http://www.somedomain.co.nz" if(!preg_match('/^(http):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):...

Matching mulitples

I need to match the following using preg_match() cats and dogs catsAndDogs i like cats and dogs etc, so i simply stripped out the spaces and lowercased it and used that as my pattern in preg_match(); '/catsanddogs/i' But now I need to match the following too: cats+and+dogs cats_and_dogs cats+and_Dogs So is there quick and easy w...

preg_replace: remove tags

I have a lot of option tags. I would like to remove the tags and get only the values. This is the code: <?php $result = preg_replace('/<option value=\"\d+\" >([A-Za-z0-9]+)<\/option>/', '$1', $result); ?> I cannot use strip_tags, strip_tags output: id="pesq_marca" class="select164" size="1" onchange="exibeModelosSelectpesq_marca(thi...

using preg_match and preg_replace

Hello. I have two strings like: http://localhost/web/ and http://localhost/web/category/ which sometimes become: http://localhost/web/2/, http://localhost/web/3/ etc.... and http://localhost/web/category/2/, http://localhost/web/category/3/ etc... I want to make a verification and: If the link is http://localhost/web/ it remain...

PHP script with regular expressions

hi there, I'm trying to get the text between the heading tag using the following php script: $search_string= < h1 >testing here< /h1 >; $text = preg_match('<%TAG%[^>]*>(.*?)</%TAG%>',$search_string, $matches); echo $matches[0]; When i try to run this script there is no value being returned. Instead there is warning message: Warn...

validate this format - "HH:MM"

Hi All, I'm trying to use preg_match to validate that a time input is in this format - "HH:MM" ...

PHP RegEx Capture with Single Quotes

Hi all, I'm trying to capture from the following string: var MyCode = "jdgsrtjd"; var ProductId = 'PX49EZ482H'; var TempPath = 'Media/Pos/'; What I'd like to get is the variable length value between the single quoted ProductId value PX49EX482H I had this, and I think it is close, but the single quotes are tripping me up. I'm not s...

PHP Regex Match parentheses

I am trying do a search to make sure that each of our product titles contains its manufacturer code. I am using preg_match but am getting some weird results back. Here is a snippet of code I wrote to go through the array of products... while($row = mysql_fetch_array($result)) { $products[''.$row[0].''][0] = $r...

php regex error, unknown modifier 'd'

Im trying to search for something on a page but i keep getting this silly error this is the error i am getting Warning: preg_match() [function.preg-match]: Unknown modifier 'd' this is the code im using $qa = file_get_contents($_GET['url']); preg_match('/<a href="/download.php\?g=(?P<number>.+)">Click here</a>/',$qa,$result); And $...

PHP function to grab all links inside a <DIV> on remote site using scrape method

Anyone has a PHP function that can grab all links inside a specific DIV on a remote site? So usage might be: $links = grab_links($url,$divname); And return an array I can use. Grabbing links I can figure out but not sure how to make it only do it within a specific div. Thanks! Scott ...

Get data only from html table used preg_match_all in php

Hi everybody, I have a html table like this : <table ... > <tbody ... > <tr ... > <td ...> string... </td> <td ...> string... </td> <td ...> string... </td> <td ...> ...

Preg match question

Hello, I'm sure someone already asked this question, but after searching for more than 1 hour on google, I decided to ask my question here. I want to itterate over an array excisting of different strings/texts. These texts contain strings with both ##valuetoreplace## and #valuetoreplace# I want to make to preg_matches: $pattern = '...