PHP - Find If Two Digits In Same Place Are The Same
I need a way to find numbers 0000-9999 where no number has more than 2 digits in the same place in common. I know PHP but this is a little beyond me, can anyone help?
Similar TutorialsHow do I get the number as pairs? (i.e. 05, 20, 01, 70) $query = "SELECT statez, COUNT(statez)FROM distributors GROUP BY statez"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['COUNT(statez)'] ." Distributors in ". $row['statez']; echo "<br />"; } ?> Hi, I'd like to know what the most efficient code is for checking the first 2 digits of a string. eg a strings first 2 digits must equal '07' thanks, Below is some PHP code that looks at a DB and outputs a value within the user declared time and date period, via user recall using a web app attached to it. The code is rounding the numbers but I want it to include 2 of the decimal places. The original numbers in the DB have up to 5 decimal digits. This code is making them whole numbers. i would like to include the first 2 digits. I suspect the float should somehow be float(2) . Not sure how to do that. thanks in advance <?php $sql = ";WITH TOTAL_FULL_ENERGY_SUM_BASE_WEEKDAY_SUMMER AS ( SELECT cdate, datepart(hh, cdate) as trans_hour, datepart(mi, cdate) as trans_minute, comm_id, max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, meter_multiplier FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] where comm_id='$comm_id' and meter_multiplier is not null group by comm_id, cdate, meter_multiplier ) SELECT top 1 *, datepart(weekday, cdate) as trans_date_day, datepart(month, cdate) as trans_date_month, datepart(hour, cdate) as trans_date_hour, DATEPART(minute, cdate) as trans_date_minute FROM TOTAL_FULL_ENERGY_SUM_BASE_WEEKDAY_SUMMER where datepart(weekday, cdate) IN ('2', '3', '4', '5', '6') AND DATEPART(MONTH, cdate) IN ('5','6','7','8','9','10') and cdate between '$base_date $base_start_time' and '$base_date $base_end_time' ORDER BY totalUsage desc"; $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ $sumUsageWKW += $row[totalUsage];}sqlsrv_free_stmt($query);?> Edited by Butterbean, 15 October 2014 - 01:31 PM. I have an integer that I'd like to validate to ensure that it is a valid number between 1 and 99999999999999999999(20 digits). I'm thinking about using the following, but I'm not sure what the max range is on the FILTER_VALIDATE_INT options. return filter_var($_REQUEST['r'], FILTER_VALIDATE_INT, array("options" => array("min_range"=>1, "max_range"=>99999999999999999999))); Can someone advise the edit required to include validation of US phone numbers ($phone_number3) when entered with no spaces between the area code and/or prefix. Note: I have working code (regular expression) that validates phone numbers that enclose the area code with parenthesis or having a space, hyphen, or dot between area code, prefix, or last four digits. Examples: all three shown below are validated based on regular expresion (123) 456-7890 123.456.7890 123 456 7890 However, I want to also include the option for 1234567890 (phone number have NO spaces) as valid. I know the edit will be within ( |-|.) using the PIPE but not sure how to denote the "no space" syntax within the regular expression. See the regular expression: $good_phone = "^\(?[0-9]{3}\)?( |-|.)[0-9]{3}(-|.)[0-9]{4}$"; and if you wan to view the entire php snippet // function which validates an American phone number function validate_phone($phone_number) { $good_phone = "^\(?[0-9]{3}\)?( |-|.)[0-9]{3}(-|.)[0-9]{4}$"; if (preg_match("/$good_phone/", $phone_number)) { echo "$phone_number is valid.<br/>"; } else echo "$phone_number is NOT valid.<br/>"; } $phone_number1 = "123.456.7890"; validate_phone($phone_number1); $phone_number2 = "(123) 456-7890"; validate_phone($phone_number2); $phone_number3 ="1234567890"; validate_phone($phone_number3); Here's what I'm wanting to do: Number = 100 In a for loop take that number, 100, and break it down into 5 random numbers to equal 100. So the for loop would output something like this: 1. 32 2. 5 3. 18 4. 9 5. 36 Total = 100 Everytime the numbers would be different. I hope that explains it Thanks! hi there - hello dear PHP-Friends, good evening! - i want to extract some data ouf of a large html-file. i have - a very very large amount of data: approx 5000 x the following line-sheme!: Quote 67003 Cato Bontjes Vice Versum House 1 28832 Achim 62042 Cato Bontjes Vice Versum House 2 28832 Achim 41798 Cato Bontjes Vice Versum House 3 37139 Adelebsen 40034 Cato Bontjes Vice Versum House 4 21365 Adendorf 46218 Cato Bontjes Vice Versum House 5 31855 Aerzen 42481Cato Bontjes Vice Versum House 6 21702 Ahlerstedt 49761 Cato Bontjes Vice Versum House 7 26197 Ahlhorn Question: how can i extract the first 5 first digits...!? I have allready some solutions here - i need a very very robuste solution diblertone1 Hi guys, I can't find any code to help me out with this so I was hoping you guys can. I need some PHP jquery/AJAX code that allows me to do the following: Double click a disabled text box, edit the value and on click out (or whatever) it re-disables and makes the chages in the mysql DB automatically. Hope you guys can help me out. Cheers in advance Hi all, I could do with some help ... What I am trying to do is insert some additional div in the piece of code you will see below, but I've been having some troubles as to what stntax I should be using and where to place those div ... In order to help you help me, I suggest you have a look at this page elhoster2.com/europeshuttle , make a search with country "sweden" as "return trip" . From there you will see 2 results. This is the page I am trying to layout. Basically, the image is on the left and then I would like to have a div floated on the left that will contain the services (multilingual driver , greeting sign etc ), another div with the info seen in bold (passengers =1, charges are per vehicle) and a last div with all pricing info. My issue is that I don't really know how to break this piece of php code to achieve the desire effect ... I hope someone will be kind enough to help me with this. Code: [Select] function get_tours($type,$country,$airport_start,$city_start,$psg,$way){ $mysql=new MYSQL; $q="select * from tours where tour_country ='$country' and tour_airport='$airport_start'and tour_city='$city_start' and tour_standard='$type' and veh_seats >='$psg'"; $res=mysql_query($q,$mysql->connection); if(mysql_num_rows($res)>0){ while($r=mysql_fetch_array($res)){echo'<form id="booking_2" action="booking-form.php" method="post">'; echo'<div class="search-results spacing-bot" ><figure class="img-indent"> <a class="lightbox-image" href="'.SITE.$r['tour_vehicle_picture'].'" data-gal="prettyPhoto[gallery1]"><img src="'.SITE.$r['tour_vehicle_picture'].'" width="188" height="138" alt=""></a></figure> <div class="search-results-info">'; #THIS IS WHERE THE SERVICE LIST BEGINS ########################################### $tour_id=$r['tour_id']; $serv="select * from services_to_tour where tour_id='$tour_id'"; $re=mysql_query($serv,$mysql->connection); while($ro=mysql_fetch_array($re)){ $serv_id=$ro['serv_id']; $this->get_serv($serv_id); } #THIS IS WHERE THE SERVICE LIST ENDS I GUESS AND THAT I WOULD LIKE TO BE IN ITS OWN DIV ########################################### #FROM HERE I AM GETTING A BIT CONFUSED WITH THE PHP AND HAVE NO IDEA HOW TO STYLE IT !!!########################################### $crg_by=$r['tour_price_per']; if($crg_by=='per vehicle'){ $crg='per vehicle'; $tour_price= $r['tour_price'] ; $tour_r=$r['tour_price_return']; $total=$r['tour_price'] + $r['tour_price_return'] ; $total_i=$r['tour_price']; $total_b=$r['tour_price_return']; } elseif($crg_by=='per person'){ $crg='per passenger';$total_i=$r['tour_price'] * $psg; $tour_price= $r['tour_price'] * $psg; $tour_r=$r['tour_price_return']* $psg; $total= $tour_price + $tour_price; } if($way=='Return'){$price='Collection: '.$tour_price.' Euros<br />Return: '.$tour_r.' Euros'; $total=$total; $amount=$total;$percent='15'; $online=$this->get_percent($amount,$percent); $pr=$online;$total='<br />Total Price: '.$total.' Euros<br />Payable online: '.$online.' Euros'; } else{$amount=$tour_price;$percent='15'; $online=$this->get_percent($amount,$percent); $price='Price: '.$tour_price.' Euros<br />Payable online: '.$online.' Euros';$total='';$pr=$r['tour_price']; $pr=$online; } echo'<span class="p1"><strong>Passengers:</strong></span> '.$psg.'<br /><span class="p1"><strong>Charges are by '.$crg.'</strong></span><br /><span class="p1"><strong>Price </strong></span><br />'.$price.$total.'<input type="hidden" name="tour_id" value="'.$tour_id.'" /> <input type="hidden" name="way" value="'.$way.'" /><input type="hidden" name="psg" value="'.$psg.'" /><input type="hidden" name="price" value="'.$pr.'" /><input type="hidden" name="price_in" value="'.$total_i.'" /><input type="hidden" name="price_out" value="'.$total_b.'" /><input type="hidden" name="operator" value="'.$r['operator_id'].'" /><a onClick="document.getElementById(\'booking_2\').submit()" class="button" style="float:right"><strong><strong>book this transfer</strong></strong></a></form> </div> <div class="border-bot"></div> </div>'; } } else{echo'<p>Sorry your search returned no results.</p>';} } I currently have a Javascript placed at the top of the same file as my HTML form. Now I need to run the file as PHP, and was wondering what the proper protocol and best practice is for the JavaScript (which does some client side validation). Can I leave it as is, at the top of the file after changing the extention to PHP. If I put it in a seperate file, should I call it as a JavaScript or as an INCLUDE file. If I INCLUDE it, should the INCLUDE be a PHP file (that contains the JS, or a JS extention. Does any of this make a difference, or will any method work, leaving it to personal preference? I have gleaned a script from modified bits of tutorials and ended up with this: <td> <form name="input" action="fotw.php" method="post"> <h4>Want a specific film? <input type="text" width="300" name="requests" /> <input type="submit" value="Request" /><input type="hidden" name="thanks" /></h4> </form> </td> <?php $requests = $_POST['requests']; $data = "$requests\n"; $fh = fopen("../filmoftheweek/users.txt", "a"); fwrite($fh, $data); fclose($fh); /*if (???????? HELP!);*/ // request button has been clicked echo "Thanks, I'll see what I can do."; // In the field I have highlighted in red ?> What I want to do is get the Thanks message to print to the right of the request button but, being a total noob because I didn't pay attention at college during any php bits, I have no idea how to go about it. It's just a visual thing really as I know the text file gets written but, disappearing text does little to reassure the user that something has happened. Probably the field won't be any good as a place to get printed but I tried (for hours) on this. Any help would be greatly appreciated. Along with an explanation, doubly so. Many thanks in advance, Paul Note to moderators: CSS is an acronym for Cascading Style..? Sheet/sheets [attachment deleted by admin] Greetings once again, My script retrieves variables from a database and pre-populates a form: Code: [Select] <input type="text"" name="First" value="<?php echo stripslashes($row['First']); ?>" > Simple to do with text fields, but not as simple for checkboxes: Code: [Select] <input type="checkbox" name="Subject" size="27" value="Math" checked> In the past I've used JavaScript to place a check in a checkbox, based on the value in the database. Can anyone show me a simple way to use PHP to place the check if the variable found in the database is in fact "Math"; but leave it it unchecked if the Subject value is empty? As always, thank you! ~Wayne I have a membership directory that I've been working with for a long time, and recent server upgrades with MySQL, PHP, etc. forced me to do some recoding. While I was doing that, I wanted to try and make some improvements. I must give a brief description of the intent, and then the results I got, so someone can sort out the problem for me. I have a query that selects all "Agent" members, then orders them by County, then by Company Name. What I am trying to do is create a new heading in my list every time the County information changes as the list is sorted and output to my table.
I am going to attache 2 .php files with my code. The agent_member_list.php is the original code that pulls all of the members properly, and results can be viewed he http://www.nmlta.org...member_list.php
The agent2_member_list.php is where I'm trying to insert the new conditional statement to print my County headings when a new County is encountered in the results. The heading actually works, and changes correctly, but the problem is that the first member entry in every county is not printed in the output. I know the query is correct, so I'm sure I've got the conditional "if" for checking County field wrong, or misplaced. Here is the link to it: http://www.nmlta.org...member_list.php
I'm hoping someone can spot my error pretty quickly, I only dabble in this very rarely. Thanks for any help!
Attached Files
agent2_member_list.php 5.06KB
3 downloads
agent_member_list.php 4.82KB
2 downloads Hiya peeps! I have this code; if(preg_match('([0-9]{5})', $this->_searchString)) { echo '5 characters, numbers only.'; } elseif(preg_match('([0-9]{7})', $this->_searchString)) { echo '7 characters, numbers only.'; } The 7 characters are not working for some reason, I have used this preg_match regex all over my script and it's working everywhere else but with this? Can anyone see any reason why it is not working? Many thanks, James. I want to create many PDF pages by using a PDF document template that uses place holders
The data would come from a CSV file
I've looked into a solution for the above for a couple of years now!
I haven't found anything that would do the trick for me
It seems as though PDF and PHP don't go well - especially if I want to use a template with place holders
Just looking for suggestions
Thanks
EDIT: forget PDF... is it possible to use something else? Like a Word doc??
OM
Edited by OM2, 05 June 2014 - 09:07 PM. Hello, I'm getting my feet wet with PHP and databases. I've read that I can provide the login for a database in a separate file, which I can place in a directory located OUTSIDE of my site (parent folder). This works fine at the isp where my site is being hosted. However, now I want to do the same thing at a site that is hosted at (ugh) GoDaddy. Unfortunately, GoDaddy does not allow access outside of the site (aka parent folder of the site). So now where am I supposed to put the file with the database login info in it so it will be secure? Thank you. Got this working script that sends email via a form:
<?php
$name = $_POST['name'];
} else { }
{ } ?>
Problem is, I want a bar to appear saying 'Message Sent. We Will Contact You Shortly'. I'm brand new to php and followed a tutorial for the above. It's a simple form that I understand, apart from the code needed for confirmation! Please can someone offer any assistance. Thanks in advance......
What would be the best way to break the following html into a table <div class="highlight">Name: CHRISTOPHER</div> <table summary="This table contains status information for the selected name."> <caption>Selected name status Information</caption> <tr> <th>Current Name:</th> <td>CHRISTOPHER</td> </tr> <tr> <th>Initial Filing Date:</th> <td>DECEMBER 15, 1997</td> </tr> <tr> <th>County:</th> <td>NEW YORK</td> </tr> <tr> <th>Jurisdiction:</th> <td>NEW YORK</td> </tr> <tr> <th>Type:</th> <td>Full Member</td> </tr> Would pregmatch or COMDocument be easier? I need my code to generate the following HTML: Code: [Select] div id="wowslider-container1"> <div class="ws_images"> <span><img src="https://alaskapac.centertix.net/UPLImage/aca_beauty.jpg" alt="Disney's Beauty & the Beast" title="Disney's Beauty & the Beast" id="wows0" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/ss_scaredscriptless.jpg" alt="Scared Scriptless" title="Scared Scriptless" id="wows1" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aysc_worldcupofwines.jpg" alt="World Cup of Wines" title="World Cup of Wines" id="wows2" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aso_outofthisworld.jpg" alt="Anchorage Symphony's Out of This World" title="Anchorage Symphony's Out of This World" id="wows3" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aca_mikegarson.jpg" alt="Mike Garson" title="Mike Garson" id="wows4" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/ctc_pinkalicious.jpg" alt="Pinkalicious!" title="Pinkalicious!" id="wows5" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aso_silentfilm.jpg" alt="Anchorage Symphony's Silent Film Double Feature" title="Anchorage Symphony's Silent Film Double Feature" id="wows6" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aca_rockofages.jpg" alt="Rock of Ages" title="Rock of Ages" id="wows7" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/pdc_concert.jpg" alt="Pulse Dance Company in Concert" title="Pulse Dance Company in Concert" id="wows8" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/aca_mannheimsteamroller.jpg" alt="The Christmas Music of Mannheim Steamroller" title="The Christmas Music of Mannheim Steamroller" id="wows9" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/alex_zlatkovski.jpg" alt="Alexander Zlatkovski" title="Alexander Zlatkovski" id="wows10" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/wsp_joshritter.jpg" alt="Josh Ritter" title="Josh Ritter" id="wows11" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/z_acpa_giftcertificates.jpg" alt="Gift Certificates" title="Gift Certificates" id="wows12" /></span> <span><img src="https://alaskapac.centertix.net/UPLImage/adp_fireice.jpg" alt="New Year's Eve Celebration" title="New Year's Eve Celebration" id="wows13" /></span> </div><div class="ws_bullets"><div> <a href="#wows0" title="Disney's Beauty & the Beast"><img src="https://alaskapac.centertix.net/UPLImage/aca_beauty.jpg" alt="Disney's Beauty & the Beast" />1</a> <a href="#wows1" title="Scared Scriptless"><img src="https://alaskapac.centertix.net/UPLImage/ss_scaredscriptless.jpg" alt="Scared Scriptless" />2</a> <a href="#wows2" title="World Cup of Wines"><img src="https://alaskapac.centertix.net/UPLImage/aysc_worldcupofwines.jpg" alt="World Cup of Wines" />3</a> <a href="#wows3" title="Anchorage Symphony's Out of This World"><img src="https://alaskapac.centertix.net/UPLImage/aso_outofthisworld.jpg" alt="Anchorage Symphony's Out of This World" />4</a> <a href="#wows4" title="Mike Garson"><img src="https://alaskapac.centertix.net/UPLImage/aca_mikegarson.jpg" alt="Mike Garson" />5</a> <a href="#wows5" title="Pinkalicious!"><img src="https://alaskapac.centertix.net/UPLImage/ctc_pinkalicious.jpg" alt="Pinkalicious!" />6</a> <a href="#wows6" title="Anchorage Symphony's Silent Film Double Feature"><img src="https://alaskapac.centertix.net/UPLImage/aso_silentfilm.jpg" alt="Anchorage Symphony's Silent Film Double Feature" />7</a> <a href="#wows7" title="Rock of Ages"><img src="https://alaskapac.centertix.net/UPLImage/aca_rockofages.jpg" alt="Rock of Ages" />8</a> <a href="#wows8" title="Pulse Dance Company in Concert"><img src="https://alaskapac.centertix.net/UPLImage/pdc_concert.jpg" alt="Pulse Dance Company in Concert" />9</a> <a href="#wows9" title="The Christmas Music of Mannheim Steamroller"><img src="https://alaskapac.centertix.net/UPLImage/aca_mannheimsteamroller.jpg" alt="The Christmas Music of Mannheim Steamroller" />10</a> <a href="#wows10" title="Alexander Zlatkovski"><img src="https://alaskapac.centertix.net/UPLImage/alex_zlatkovski.jpg" alt="Alexander Zlatkovski" />11</a> <a href="#wows11" title="Josh Ritter"><img src="https://alaskapac.centertix.net/UPLImage/wsp_joshritter.jpg" alt="Josh Ritter" />12</a> <a href="#wows12" title="Gift Certificates"><img src="https://alaskapac.centertix.net/UPLImage/z_acpa_giftcertificates.jpg" alt="Gift Certificates" />13</a> <a href="#wows13" title="New Year's Eve Celebration"><img src="https://alaskapac.centertix.net/UPLImage/adp_fireice.jpg" alt="New Year's Eve Celebration" />14</a> </div></div> </div> So I assumed that it would be something similar to the following: Code: [Select] while ($Row = mysqli_fetch_assoc($carouselResult)){ $EventName = $Row['EventTitle']; $image = $Row['eImage']; /* $big_image = LISTING OF ALL IMAGES */ $big_image = array('<span><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" title="' . $EventName . '" id="wows'. $i .'" /></span>'."\n"); $i2 = $i; $i = $i+1; /* $nav_image = TINY BOXES TO NAVIGATE THROUGHOUT CAROUSEL */ $nav_image = array('<a href="#wows' . $i2 . '" title="'.$EventName.'"><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" />'.$i.'</a>'."\n"); $i2 = $i2+1; } echo '<div id="wowslider-container1">'."\n".'<div class="ws_images">'."\n"; echo array($big_image); echo '</div><div class="ws_bullets"><div>'."\n"; echo array($nav_image); echo '</div></div>'."\n".'</div>'; But array($big_image) and array($nav_image) do not work as I expected and it just produces the following HTML code: Code: [Select] <div id="wowslider-container1"> <div class="ws_images"> Array</div><div class="ws_bullets"><div> Array</div></div> </div> Can anyone help out a beginner in PHP? |