title: fetching all the data from the database based on user input matching only some part of a field in database using php
body: <p>I have IP address like below in my database.</p>
  
  <p>10.00.54.58, 10.75.103.101, 10.50.44.11</p>
  
  <p>I am taking user input for IP address. I want the user to fetch all the data even if the user enters any of the ip(in this case either he enters 10.00.54.58 or 10.75.103.101 or 10.50.44.11), he should get all the data based on that filter.</p>
  
  <p>How can i modify my below code so that it fetches all data based on any of the IP address. Or can i make a separate function and call it here. Kindly help</p>
  
  <p>Given :</p>
  
  <p>const REGEXP_SECLOGS_IP = "/^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/";</p>
  
  <pre><code> $requestObj = new PagesviewlogEventRequest();
              $requestObj-&gt;userid = (Utils::validatePattern(Utils::REGEXP_SECLOGS_USERID, (($_POST['userid']) ?? FALSE) )) ? $_POST['userid']:FALSE;
              $requestObj-&gt;fromdate = (Utils::validatePattern(Utils::REGEXP_DATE_ZULU, (($_POST['startdate']) ?? FALSE) )) ? $_POST['startdate']:NULL;
              $requestObj-&gt;todate = (Utils::validatePattern(Utils::REGEXP_DATE_ZULU, (($_POST['enddate']) ?? FALSE) )) ? $_POST['enddate']:NULL;
              $requestObj-&gt;clientip = (Utils::validatePattern(Utils::REGEXP_SECLOGS_IP, (($_POST['clientip']) ?? FALSE) )) ? $_POST['clientip']:FALSE;
              $requestObj-&gt;limit = (Utils::validatePattern(Utils::REGEXP_SECLOGS_LIMIT, (($_POST['limit']) ?? FALSE) )) ? $_POST['limit']:'';
  </code></pre>
  
  <p>I tried to create a function and later on call it in the above code but not sure how to proceed:</p>
  
  <pre><code>public static function getIPRegexp()
      {
          $clientip = explode(", ",$clientip);
          foreach ($clientip as $key =&gt; $value) {
  
             preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/",$clientip, $matches);
          }
      }
  </code></pre>
  
  <p>Kindly help. I am new to php so any help will be appreciated. Thanks in advance</p>