PHP - Tiny Preg_match_all Trouble - Match Any Url On A Domain.
preg_match_all('/(www.DOMAIN.com\/([^"]+))\"/i', $html, $matches);
How do you make this match any URL on the domain including URLs with ? = & type of characters. Similar Tutorialshey guys im making a script where the user gets redirected...but im wanting to make sure the redirection is within the same domain and not being shipped off to another site when using ($_SERVER['HTTP_REFERER'])
now what im using seems to do the trick but im wondering if there is a better method of doing this?...i dont want to use regex either
thank you guys
<?php $match = strpos("http://127.0.0.1/login", $_SERVER['SERVER_NAME']); if ($match && $match > 0 || $match === 0) { echo "domain match"; } ?> Hello again, I have some form data, which I then search through for particular code data like so: $html2 = $_POST['fname']; preg_match_all("/<bla>(.*)<\/bla>/", $html2, $matches40); So the above searches for all the data between <bla>XXXXXX</bla> from $POST Which I then print to my page using: (Only so I can see while developing) print_r($matches40); This displays HTML output like so: Code: [Select] Array ( [0] => Array ( [0] => Hello [1] => My [2] => Name [3] => Is [4] => Tom ) [1] => Array ( [0] => Hello [1] => My [2] => Name [3] => Is [4] => Tom ) ) What I am trying to do is again use the preg_match_all function to look through the array output and find data that I want to remove. E.g. If one of the variables from $matches40 is 'Tom' I want to find and replaces this with 'Ben'. I spent a day searching Google but to not success. Any help? I have two domains both running SSL. Let's call them old-domain and new-domain. old-domain is permanently redirecting traffic to new-domain. There are still a lot of links out there to old-domain with https://. If I were to remove SSL from old-domain but keep SSL on new-domain, I am betting that users will be getting some sort of certificate error. Right? Any way around that if I want to remove SSL from old-domain?
This topic has been moved to the corner of 3rd Avenue and mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359430.0 Hello nice php experts :-) I've just changed the theme on my wordpress page but wish to add a couple of links to my non-wordpress pages to it. This is the line of code where I wish to add some more links. I'm going to use the page-link class to format the links but I'm not sure where I would add the extra divs in amongst all of those commas and brackets. <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', '' ), 'after' => '</div>' ) ); ?> Any help is gratefully accepted. I am trying to update a tiny int i have the if statement which says when tiny int is 1 echo closed and when tiny int 0 echo open. The problem is i am trying to query the result in a drop down but the option of status Closed doesnt appear. Code: [Select] <?php //connect to database $con=mysql_connect("localhost","root","15AE@ea27") or die("couldn't connect to mysql"); //select database $db=mysql_select_db("ac_res",$con) or die("database not found"); //get ID to Edit $id = $_GET['id']; //Query Fields to edit $sql = 'SELECT * FROM `ac_reservation` WHERE `id` = "'.$id.'"'; $query = mysql_query($sql) or die("Couldn't execute query. ". mysql_error()); $results = mysql_fetch_array($query); $status = 'status'; //Query the waiter table $waiter=mysql_query("SELECT fname FROM waiter") or die("query error"); ?> <form id="edituser" name="edituser" method="post" action="editresexec.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th> </th> <td><input name="id" type="hidden" class="textfield" value= <?php echo $results[id]?> /> </td> </tr> <tr> <th>First Name </th> <td><input name="fl_name" id="keyboard2" type="text" class="textfield" value= <?php echo $results[fl_name]?> /> </td> </tr> <tr> <th>Number of People</th> <td><input name="n_people" id="keyboard3" type="text" class="textfield" value= <?php echo $results[n_people]?> /> </td> </tr> <tr> <th>Table Number</th> <td><input id="t_number"name="t_number" type="text" class="textfield" value= <?php echo $results[t_number]?> /></td> </tr> <tr> <th>Waiter</th> <td><?php echo "<select name=waiter>"; while($r=mysql_fetch_array($waiter)) { //echo waiter name echo "<option value='".$r['fname']."'>".$r['fname']."</option>"; } echo "</select>"; ?> </td> </tr> <tr> <th>Status</th> <td><?php //If statement if($rows['status'] == 1) { $status = "Close"; } else $status = "Open"; //Drop Down Menu For Status echo "<select>"; echo "<option value='".$status."'>".$status."</option>"; echo "</select>"; ?> </td> </tr> <tr> <td> </td> <td><input type="submit" name="Update" value="Update" /></td> </tr> </table> </form> I use the following code to create a 48x7 array for my application: Code: [Select] // Loop through each time division for($i=0; $i<$div; $i++) { // Loop through the week we're displaying for($j=0;$j<$dayPerPage; $j++) { $dateArray = getDate( mktime( 0, 0, 0, date("m"), date("d")+$j+$dateOffset, date("Y") ) ); $date = sprintf('%04d-%02d-%02d',$dateArray["year"],$dateArray["mon"],$dateArray["mday"]); $datetime[]="$time|$date"; list($start_date) = explode('|',$datetime[1]); list($end_date) = explode('|',end($datetime)); } $min += $step_size; if($min >= 60) { $min = 0; $hr++; } $time = sprintf('%02d:%02d:00',$hr,$min); }Now, I'm under the assumption that list($start_date) and list($end_date) should give me the beginning and ending dates inside the array (say 2011-10-01 and 2011-10-07), but instead I get the beginning and ending times in it ('00:00:00' AND '23:30:00'). Could someone clarify what I'm doing wrong and how I can fix it? I'm really new to php EDIT: Sorry... used the wrong tags for the code the first time around. Fixed. i want to find the text between "{:" and ":}", may be 1 or more instances of this i'm using this php: $str = "hello {:first_name:} ha, this is {:awesome:} haha"; $do = preg_match_all("/{:(.*):}/", $str, $matches); which works if theres just one instance, but when you use more than 1 instance (like the above example) it returns: first_name:} ha, this is {:awesome But i want it to return a value of first_name, AND a separate value of "awesome" ideas? thanks I am trying to use preg_match_all to find some information on a webpage. Here is what I am currently using <?php $homepage = "http://www.example.com"; $page_contents1 = file_get_contents($homepage); $names1 = preg_match_all('/<span class="video_date">(.*)</span> - <a class="b" href="/(.*)/">(.*)</a><br/>\/', $page_contents1, $matches1); echo implode(", ", $matches1[1]); ?> I am trying to match this piece of html: <span class="video_date">Oct 21</span> - <a class="b" href="/meanwhilezealand/"> Meanwhile in New Zealand...</a><br/> Thanks for looking! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=328802.0 Hi there i have this code: Code: [Select] $str = "<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>"; $pattern = '/<font .*?>(.*?)<\/font>/'; if(preg_match_all($pattern, addslashes($str), $posts)){ $i=0; for($i; $i < count($posts[0]); $i++){ echo "content: " . $posts[0][$i] . "<br/>"; echo "colour: " . $posts[1][$i] . "<br/>"; echo "<br />"; } } and it doesn't work apparently because of the addslashes but its really needed as double quotes needs to be escaped, consider that i'm applying this code to a larger html file with hundreds of double quotes to be escaped.... error msg i get is Parse error: syntax error, unexpected T_LNUMBER in thanks in advance.. This is rather bothering as I know if you use the delimiter / regex pattern s it should ignore newlines preg_match_all("%<p><b>(.*?)</b>%s", $html, $data); Returns a blank array the page data is like so <p> <b>41,910</b><br/> Total Points </p> Never had a problem before that i can recall but for some reason with this page it's giving me issues. Maybe i'm missing something? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=348635.0 Hello all! So I am working on screen scraping a site for my son's rec league. I seem to be having problem with the pre_match_all syntax. Here is my code Code: [Select] <?php $url = "http://www.mywebsite.com"; $raw = file_get_contents($url); $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); $content = str_replace($newlines, "", html_entity_decode($raw)); $start = strpos($content,'table border="1" cellpadding="1" cellspacing="0"'); $end = strpos($content,'</table>',$start) + 8; $table = substr($content,$start,$end-$start); preg_match_all("|<tr(.*)</tr>|U",$table,$rows); foreach ($rows[0] as $row){ if ((strpos($row,'<th')===false)){ preg_match_all("|<td(.*)</td>|U",$row,$cells); $game_date = strip_tags($cells[0][0]); $game_time = strip_tags($cells[0][1]); $rink = strip_tags($cells[0][2]); $home_team = strip_tags($cells[0][3]); $home_score = strip_tags($cells[0][4]); $visiting_team = strip_tags($cells[0][5]); $visiting_score = strip_tags($cells[0][6]); echo "{$game_date} @ {$game_time} : [{$home_team}] - {$home_score} vs. [{$visiting_team}] - {$visiting_score} <br>\n"; } } ?> My issue is that I am trying to get it to only display the data if the team name = x. I tried to replace the preg_match_all("|<td(.*)</td>|U",$row,$cells); with preg_match_all("|Posse|U",$row,$cells); (Posse is one of the team names). No luck. Any input/thoughts?! Thank you!! I have noticed that if I run the preg_match_all function and use PREG_OFFSET_CAPTURE option to start capture somwhere in the middle of the string the second half of the string will be searched first returning the matching sections along with positions, then it goes up to the top half and returns matches from there too. Is there way to parse only between start point and end of string? Sorry in advance for my lack of knowledge. I am not trained and I know almost zero about site building. On my site there is a tiny rectangle that is showing up on a drop down menu... It hasn't always been there. I'm pretty sure it showed up after upgrading to the newest Internet Explorer. I've been staring at it and finally decided to figure out what it is doing there.... Please, any and all help will be greatly appreciated. The rectangle is not hindering the site, it is just an eye sore. Thanks in advance! Yelhsa See Attachment for Screenshot. Link to Site: www.georgiafarmandforest.com Coding (this is the drop down menu part of the coding, I don't know if you need more than this.... If so, does viewing the source work?): Menu1=new Array("Home","index.php","",0,20,140); Menu2=new Array("Counties","#","",11,0,140); Menu2_1=new Array("Bartow","bartow.php","",0,20,140); Menu2_2=new Array("Carroll","carroll.php","",0,20,0); Menu2_3=new Array("Catoosa","catoosa.php","",0,20,140); Menu2_4=new Array("Chattooga","chattooga.php","",0,20,140); Menu2_5=new Array("Dade","dade.php","",0,20,140); Menu2_6=new Array("Floyd","floyd.php","",0,20,140); Menu2_7=new Array("Gordon","gordon.php","",0,20,140); Menu2_8=new Array("Murray","murray.php","",0,20,140); Menu2_9=new Array("Polk","polk.php","",0,20,140); Menu2_10=new Array("Walker","walker.php","",0,20,140); Menu2_11=new Array("Whitfield","whitfield.php","",0,20,80); Menu3=new Array("Resources","resources.php","",0,0,140); Menu4=new Array("Contact Us","contact.php","",0,20,140); Menu5=new Array("Submit Land Wanted","submit.php","",0,0,160); Hi, I have the written the following code which scrapes price info from a website: $url = 'http://www.mydomain.com'; $html = file_get_contents($url); $pattern = '/<span class="price">(.*?)<\/span>/'; preg_match_all($pattern, $html, $matches); print_r($matches); It works well however I need to add in the delivery cost to each array element with a different pattern: /<span class="delivery">(.*?)<\/span>/'; Any idea how i can do this so each array element has both the price and delivery costs in a two dimensional array? Thanks for your advice For example. I have the following: Andrew (Age 19) How would I get the content between the brackets, Age 19 using preg_match_all or a similar function? Thanks very much Hello, i am trying to pull the innerHTML out of this: Code: [Select] <a href="(.*?)">(.*?)</a> here is what I have: Code: [Select] <?php $html = file_get_contents("http://www.businessinvestingsource.com/blcheck2.html"); preg_match_all('/<a href="(.*?)">(.*?)<\/a>/', $html, $links, PREG_SET_ORDER); foreach ($links as $link) { $linkto = $link[1]; $anchor = $link[0]; echo "<b>Link:</b> ".$linkto."<br /><b>Anchor:</b> ".$anchor."<br /><br /> "; } ?> Now this code works but the innerHTML is coming out as a link I want it to come out as plaintext you can view he http://businessinvestingsource.com/anchorcheck2.php Can anyone help? Thank you. |