Jump to content

i

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

About i

  • Birthday 02/20/1954

Contact Methods

  • Website URL
    http://aLanTait.com

Profile Information

  • Gender
    Male
  • Location
    Talisay City, Cebu, Philippines

i's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. If it solves it for you, don't forget to mark it solved!
  2. Hi BlueBuffalo, I am NOT an expert! I'm just playing with friends that "play nice" and are willing to work out a solution. I have never failed to find a solution it if was possible (except how to code an "&" into a $_GET var in a URL! Ha Ha! Anyway, I do think what you are asking can be done. Since I posted, I wrote a script that validates phone numbers for a local Ad site (But & Sell on the Internet) here in the Philippines. The normal here is to ask for Country Code, Area Code and Phone number as separate Input fields. Think of $fonCC $fonArea and $fonNum - and the same for cell and fax (or work or home). You could put it in an array if you prefer. I validate and store each of these separately because I use them for different things (for example, a person in the +63 country is in the Philippines and I do not need to ask them what country is their address in! My validation is simple, I get rid of everything but numbers and ltrim leading 0's and check the result length against what is acceptable! For example 1-2 letters for an area code, 3,4, or 5 numbers for an extended area code. 4-7 numbers for a phone number. All that means is that a Philippine area code / phone number needs to be 9 digits if it is anywhere except Manila (area code "2") and 8 digits if it is in Manila. I end up with a 1-2 digit area code and a 7 digit phone number. (I deal with CC's separately). Being from the "Land of the Free and the home of the Braves!" (At least my brother lives in Atlanta!) I recognized your xxx-xxx-xxxx pattern ASAP. Being one of the guys who actually helped put that into Ma Bell and GTE back before computers ran telephones as an advantage! Anyway if I were you... <?php $phone = array('1 - (0)(213)3701234 - Thats My Phone Number!', '','213-5555-1212'); // $phone = array('', '',''); // $phone = array('1<418>5555-1212', '','1(213-3722-1234'); // $phone = array('', '4145552674','2142141212'); // $phone = array('1(0)(213)3701234', '0(212)674-3331','214-214-1212'); // Print the Array Just to see what is there! echo 'Our Array at the Beginning!<br /><pre>'; print_r($phone); echo '</pre><br /><br />'; // Loop One - The Input Loop from the Form - you get an array called $phone... for ($i = 0; $i <= 2; $i++) { // Strip everything but the numbers... $phone[$i] = preg_replace("![^0-9.]!", "", $phone[$i]); // Phone Numbers Do Not Start with a Zero or One! $phone[$i] = ltrim($phone[$i], "01"); // Is our format valid? 10 Digits is great! Zero is empty! switch (true) { case ($phone[$i] == 0): $phone["test$i"] = 'empty'; break; case (strlen($phone[$i]) == 10): $phone["test$i"] = 'pass'; break; case (strlen($phone[$i]) > 0): $phone["test$i"] = 'wrong'; break; default: $phone["test$i"] = 'error - Note: If you ever get this, the world has ended and you are dead!'; } } // I have a friend, she calls me Neo, I call her Switch! switch (true) { case ($phone['test0'] == 'pass'): case ($phone['test1'] == 'pass'): case ($phone['test2'] == 'pass'): $phone['oneOf3phones'] = 'YES! This guy is a good guy!'; break; default: $phone['oneOf3phones'] = 'No! These Three Numbers are NOT GOOD!' ; } // And the Winner is: // Print the Array Just to see what is there! echo 'Our Array at the End of Loop ONE!<br /><pre>'; print_r($phone); echo '</pre><br />'; //Loop 2 - Maybe an Output Loop fed from MySQL ~OR~ the continuation of Input to store numbers in the xxx-xxx-xxxx format in MySQL // Loop 2 Can also be used for addiional validation... for ($i = 0; $i <= 2; $i++) { if ($phone["test$i"] == 'pass') { // Comment this line if you want to break down nmbers that are empty, wrong or in error... $phone["fon$i"]['part1'] = substr($phone[$i],0,3); $phone["fon$i"]['part2'] = substr($phone[$i],3,3); $phone["fon$i"]['part3'] = substr($phone[$i],6,7); ////////////////////////////////////////////////////////////////// // Area Codes Do Not Start with a Zero or One! $phone["fon$i"]['part2'] = ltrim($phone["fon$i"]['part2'], "01"); // You may also want to test for an area code like 555 that may be used to enter a common bogus phone number to defeat your test... // Is our Area Code Three Digits! Zero is empty! switch (true) { case ($phone["fon$i"]['part2'] == 0): $phone["test$i"] = 'empty'; break; case ($phone["fon$i"]['part2'] == 555): $phone["test$i"] = 'cheater'; break; // Needs more code because Cheaters still pass! case (strlen($phone["fon$i"]['part2']) == 3): $phone["Phone$i"] = implode('-',$phone["fon$i"]); break; case (strlen($phone["fon$i"]['part2']) > 0): $phone["test$i"] = 'wrong'; break; default: $phone["test$i"] = 'error - Note: If you ever get this, There is a Terminator at your door!'; } } } // Print the Array Just to see what is there! echo 'Our Array at the End!<br /><pre>'; print_r($phone); echo '</pre><br />'; ?> This code produces this kind of results... <?php $phone = array('1(0)(213)3701234', '0(212)674-3331','214-214-1212'); ?> Our Array at the Beginning! Array ( [0] => 1(0)(213)3701234 [1] => 0(212)674-3331 [2] => 214-214-1212 ) Our Array at the End of Loop ONE! Array ( [0] => 2133701234 [1] => 2126743331 [2] => 2142141212 [test0] => pass [test1] => pass [test2] => pass [oneOf3phones] => YES! This guy is a good guy! ) Our Array at the End! Array ( [0] => 2133701234 [1] => 2126743331 [2] => 2142141212 [test0] => pass [test1] => pass [test2] => pass [oneOf3phones] => YES! This guy is a good guy! [fon0] => Array ( [part1] => 213 [part2] => 370 [part3] => 1234 ) [Phone0] => 213-370-1234 [fon1] => Array ( [part1] => 212 [part2] => 674 [part3] => 3331 ) [Phone1] => 212-674-3331 [fon2] => Array ( [part1] => 214 [part2] => 214 [part3] => 1212 ) [Phone2] => 214-214-1212 ) <?php $phone = array('', '4145552674','2142141212'); ?> Our Array at the Beginning! Array ( [0] => [1] => 4145552674 [2] => 2142141212 ) Our Array at the End of Loop ONE! Array ( [0] => [1] => 4145552674 [2] => 2142141212 [test0] => empty [test1] => pass [test2] => pass [oneOf3phones] => YES! This guy is a good guy! ) Our Array at the End! Array ( [0] => [1] => 4145552674 [2] => 2142141212 [test0] => empty [test1] => cheater [test2] => pass [oneOf3phones] => YES! This guy is a good guy! [fon1] => Array ( [part1] => 414 [part2] => 555 [part3] => 2674 ) [fon2] => Array ( [part1] => 214 [part2] => 214 [part3] => 1212 ) [Phone2] => 214-214-1212 ) <?php $phone = array('1<418>5555-1212', '','1(213-3722-1234'); ?> Our Array at the Beginning! Array ( [0] => 1<418>5555-1212 [1] => [2] => 1(213-3722-1234 ) Our Array at the End of Loop ONE! Array ( [0] => 41855551212 [1] => [2] => 21337221234 [test0] => wrong [test1] => empty [test2] => wrong [oneOf3phones] => No! These Three Numbers are NOT GOOD! ) Our Array at the End! Array ( [0] => 41855551212 [1] => [2] => 21337221234 [test0] => wrong [test1] => empty [test2] => wrong [oneOf3phones] => No! These Three Numbers are NOT GOOD! ) <?php $phone = array('', '',''); ?> Our Array at the Beginning! Array ( [0] => [1] => [2] => ) Our Array at the End of Loop ONE! Array ( [0] => [1] => [2] => [test0] => empty [test1] => empty [test2] => empty [oneOf3phones] => No! These Three Numbers are NOT GOOD! ) Our Array at the End! Array ( [0] => [1] => [2] => [test0] => empty [test1] => empty [test2] => empty [oneOf3phones] => No! These Three Numbers are NOT GOOD! ) <?php $phone = array('1 - (0)(213)3701234 - Thats My Phone Number!', '','213-5555-1212'); ?> Our Array at the Beginning! Array ( [0] => 1 - (0)(213)3701234 - Thats My Phone Number! [1] => [2] => 213-5555-1212 ) Our Array at the End of Loop ONE! Array ( [0] => 2133701234 [1] => [2] => 21355551212 [test0] => pass [test1] => empty [test2] => wrong [oneOf3phones] => YES! This guy is a good guy! ) Our Array at the End! Array ( [0] => 2133701234 [1] => [2] => 21355551212 [test0] => pass [test1] => empty [test2] => wrong [oneOf3phones] => YES! This guy is a good guy! [fon0] => Array ( [part1] => 213 [part2] => 370 [part3] => 1234 ) [Phone0] => 213-370-1234 ) Well, I am sure there will be suggestions for improvements but this will give you a start on how to code this... DarkSuperHero - Thanks for the Links - they help! Can you post a little snippet of code so show what you mean? Thanks, Lan PS: My wife beat you too it! She suggested using the Country code to determine the area code and the phone size. So far I am seeing certain patterns... For example in Japan and the Philippines, the area codes get longer when the area gets smaller in size of people. However, the telephone numbers also are getting smaller to serve the smaller number of people. So if you have a two digit area code, you have a seven digit number. Likewise a five digit area code will get you a four digit number. In the Philippines, the numbers add up to nine digits! In Japan they add up to 10 digits like in the USA. They just call them different names! Talaga! (Filipino for Really!)
  3. Just remember that echo outputs - so if you get a header or session problem it may be your echos! - Lan
  4. Wow Daniel, I woke up this morning to one of those, "gee I wish I said that" moments upon reading this! I actually started doing just that! With a twist... Like everyone (no one knows everything about PHP), I have new projects with new challenges. I'm new here, but I now come, look for a person in PHP Help with a problem like mine, and then try to solve it for us both! I benefit from what they already tried and what they were thinking and any ideas they had, and they benefit from whatever experience or help I can provide them. PHP Freaks is a win/win for me. But your words are really, "words of wisdom" - the only way anyone knows if they can program is if they write some code, make some errors, and fix them. As my old mentor in Cobol said...
  5. My Wife Likes: http://devzone.zend.com/node/view/id/627 I like: http://www.w3schools.com/PHP/DEfaULT.asP We have also benefited from... http://www.php.net/tut.php http://www.tizag.com/phpT/ http://www.goodphptutorials.com/
  6. http://www.php.net/manual/en/reserved.variables.server.php $_SERVER['HTTP_REFERER'] <?php if ($_SERVER['HTTP_REFERER'] == 'http://something') { header(Location:'http://somewhere') ; } elseif ($_SERVER['HTTP_REFERER'] == 'http://something_else') { header(Location:'http://somewhere_else') ; } ?> This has real limitations. First, it must come from a page that links to your page. If you click a link in your bookmarks you get nothing - the same with typing a url... And some servers will not pass this information on to you! Finally, you get the full URL - that includes gets and path and everything, If you want just the Domain name you will have to condition it a bit.
  7. No offense taken Axeia, In fact I agree with you! As for my "java" post - gee, I think that was a javaSlip, or even a java spill! All I can say is too many late nights == blame it on the Philippine Time Zone! I need another cup of hot java juice! That was a really a java beaner I pulled! However, You made my point exactly... The other point being that php validation does not have to press the back button! (see frost110 post above that recommends dumping PHP validation and just using JavaScript). I do agree with you there... Although even that point is going by the wayside as server speeds and Internet speeds increase. Yet, I often write the PHP form validation and when all is well I take the RegEx's from the PHP and do JavaScript to do the same thing. The JavaScript pre-conditions the data and gives the client the feel of "speed" while the PHP locks up the security! Now that we got all that straighten out... Thanks for the drupal downloads. I have read a few of their RegEx's. It is interesting to me that they are using a (444) 867-5309 x1234 format for the North American +! country code... The International standards would make it... +1 444 867 5309 and I am not sure what they would do with the extension... x1234. I think I am going to have to go get another cup of Java (!Script) and think over what to do about extensions! For the Record Axeia, I am a dinosaur on the Internet. I haven't been programing for 10 years (Actually I have been doing it 37 years - back to the days of Fortran and Cobol and ARPANET and my late good friend Jon Postel (Mr. Internet!)). I have just been doing PHP for 10 years! Thanks again for the drupal link, it has a lot of good information about the format of telephone numbers in Europe. LAN - (hey, I didn't write that on my birth certificate when I was a day old!) Maybe the Nurse had too much $Java = 'black coffee' ; back in the early 50's!
  8. Hello Yesideez. I am new to this site, but I've been hanging around PHP for a dozen years of playing! I feel for you. I am teaching my wife PHP now and I keep telling her to look for the extra spaces... Wait till I start telling her to look for the invisible spaces! So I will share few of my favorite debug tips... Remember that all php starts in html mode. Even the end of file! That means that until you get the first <?php it is in html mode. A Comment A little trick I have done for years is to put the file name in a comment at the beginning... <?php // myclass.php ?> See if that solves some problems for you on the empty files you are including. exit; The next debug friend you will want to know is... <?php exit; ?> exit; stops processing. Try your myclass.php: <?php echo 'test'; ?> Like This... <?php echo 'test'; exit; ?> You can use exit; to debug a lot of stuff because you can see in your script where the error vanishes! echo ... it makes output! In your class look for any echo statement. any echo produces output. So in your class all echo statements must be in a condition statement (like if) to prevent it from running if you have it before your session_start();. As for me I would start the session first. This may not be php, this may be CSS. <div style="background-color:#f00"> <?php include('myfile.php'); ?> </div> in myfile.php <?php echo 'test'; ?> When you see it in your browser - view the html webpage source. It should say... <div style="background-color:#f00"> test </div> check your CSS for html, body, and div Might I suggest you modify your first code to be... <div style="background-color:#f00"> <p><?php include('myfile.php'); ?></p> </div> in myfile.php <?php echo 'test'; ?> That's html I know, but would use the CSS for p instead of for html, body or div... You may also want to do it this way... <div style="background-color:#f00"> <?php include('myfile.php'); ?> </div> in myfile.php <?php echo '<p>test</p>'; ?> Either way the html view source on your browser would give you... <div style="background-color:#f00"> <p>test</p> </div> One of the things I am teaching my wife to do is to try things without the php! If you change: <div style="background-color:#f00"> <?php include('myfile.php'); ?> </div> To: <div style="background-color:#f00"> test </div> Do you get the same wide test with 14px of red padding? If yes, then your php is correct and your html or css is in need... Your php is just inserting something into your html, but your html and css still have to be correct! I have my wife write pure html and then use php to replace what she needs to... <div style="background-color:#f00"> <p>My name is Percy Andes Tait</p> </div> With that working fine, looking just the way she wants it... then modify it... <?php $first_name = 'Percy'; $mid_name = 'Andes'; $last_name = 'Tait'; ?> <div style="background-color:#f00"> <p>My name is <?php echo $first_name;?> <?php echo $mid_name;?> <?php echo $last_name;?></p> </div> Now that looks good split it into two files... <div style="background-color:#f00"> <?php include('myfile.php'); ?> <p>My name is <?php echo $first_name;?> <?php echo $mid_name;?> <?php echo $last_name;?></p> </div> And myfile.php... <?php $first_name = 'Percy'; $mid_name = 'Andes'; $last_name = 'Tait'; ?> Take notice that the myfile.php has NO echo statements! return; Another debug friend of mine is: <?php return; ?> You have 15 functions and one of them is giving you an extra space... which one??? <?php function one () ... ... return; function two () ... ... ?> That return; is NOT part of the function, it is between the first and second,,, you just forget about the rest of the include page... On your myfile.php page try this... <?php return; echo '<p>test</p>'; ?> and this... <?php echo '<p>test</p>'; return; ?> You can start by putting return; at the top of your page and then working it's way down till you find where php is doing something... like out putting that extra space! I hope this helps you, Lan
  9. I know this is an old post... did you get an answer? Your Question intrigues me as I am now working on a function the will validate phone numbers input from people in 172 countries! Likewise I plan to ask Cell and Land Line and perhaps work phone info and require that one of those be complete! Right now I am doing research on all the different syntax for phone numbers around the world. So before I reinvent the wheel on the 1 out of three phone number issue... Can you post whatever results you had? Thanks... Lan PS to frost110 I have been working with PHP for more than ten years, beck when it was called "Personal Home Page Tools". Frankly, I would never allow an... PHP has wonderful ways to verify information, and if in error, to bring the client back to exactly the place where the error is without reloading or going back to anything and also displaying exactly what the error is and what is should be... In different languages if needed! I like java and I use it for a few things, but for security nothing you put on a clients computer will ever compare with the server side scripting of PHP. Plus, personally, I have never seen a java form verification that could do anything that properly written PHP code could not do also.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.