String Manipulation Problem

Discussion in 'PHP' started by drdavisjr, Aug 19, 2007.

  1. #1
    I have a veru simple problem, maybe someone can help.

    I have a simple webform that is using method=get.

    A number is being searched for in my database. In the database the number is in the format 123-456789. I want the user to be able to enter either 123456789 or 123-456789 and still get the desired results.

    Here is my code.

    <?php 
    	include_once "shared/ez_sql_core.php";
    	include_once "ez_sql_mysql.php";
    	$db = new ezSQL_mysql('root','xxxxxxxxxxxx','refunds','localhost');
    	$claimno = $_GET['claimno'];
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <style type="text/css">
    <!--
    .style1 {color: #0000FF}
    .style2 {color: #000000}
    -->
    </style></head>
    
    <body>
    <div id="content_frame">
    <div id="header"></div>
    <div id-"main_content">
    <div class="left">
    <h1>JICS Corporation</h1>
    <p style="margin-top:-20px">US Government Refunds • Refund Assistance Processing Division</p>
    </div>
    <div class="right">
    <p style="margin-top:10px">State License# C2450647 • JICSCorp@ca.rr.com<br />
    P.O. Box 1966, Hawaiian Gardens, CA 90716</p>
    </div>
    <p class="disclaimer"><em>Note:  Due to high volume of refunds, we only accept email inquiry  @ </em>JICSCORP@CA.RR.COM</em></p>
    <?php if (isset($claimno)) { 
    $user = $db->get_row("SELECT * FROM refunds WHERE CLAIMNO = '$claimno'");
    echo $user-> SPOUSE1; echo "/"; echo $user->SPOUSE2;}
    else { ?>
    <div class="form">
    <form id="form1" name="form1" method="get" action="index.php">
      <label>
        <input name="claimno" type="text" id="textfield" value="Please Enter Your Claim Number Here!" size="40" maxlength="65" />
        </label>
        <label>
        <input type="submit" name="button" id="button" value="Check Number" />
        </label>
          </form>
    <?php }?>
    </div></div></div>
    </body>
    </html>
    Code (markup):

    Any help would be greatly appreciated.
     
    drdavisjr, Aug 19, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Untested, but should work.
    
    $claimno = preg_replace(array('/[^\d]/', '/^(\d{3})(\d+)/'), array(null, '$1-$2'), $claimno);
    
    PHP:
     
    nico_swd, Aug 19, 2007 IP
    drdavisjr likes this.
  3. drdavisjr

    drdavisjr Peon

    Messages:
    324
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a billion!!!! Works like a charm!
     
    drdavisjr, Aug 19, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    A billion is just the right amount. You're welcome. :D
     
    nico_swd, Aug 19, 2007 IP