<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: leichengde</title>
    <description>The latest articles on DEV Community by leichengde (@leichengde).</description>
    <link>https://dev.to/leichengde</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F886152%2F9e752724-3cf8-4dd8-8c80-c834651dff06.png</url>
      <title>DEV Community: leichengde</title>
      <link>https://dev.to/leichengde</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leichengde"/>
    <language>en</language>
    <item>
      <title>How to extract the first set of numbers in a string using PHP</title>
      <dc:creator>leichengde</dc:creator>
      <pubDate>Sat, 23 Jul 2022 00:26:16 +0000</pubDate>
      <link>https://dev.to/leichengde/how-to-extract-the-first-set-of-numbers-in-a-string-using-php-2l5g</link>
      <guid>https://dev.to/leichengde/how-to-extract-the-first-set-of-numbers-in-a-string-using-php-2l5g</guid>
      <description>&lt;p&gt;&lt;a href="https://allgoodsfree.com/how-to-extract-the-first-set-of-numbers-in-a-string-using-php/"&gt;How to extract the first set of numbers in a string using PHP&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;?php&lt;br&gt;
    $str='acc123nmnm4545';&lt;br&gt;
    if(preg_match('/\d+/',$str,$arr)){&lt;br&gt;
       echo $arr[0];&lt;br&gt;
    }&lt;br&gt;
?&amp;gt;&lt;/p&gt;

&lt;p&gt;Other ways to extract numbers from strings in PHP&lt;/p&gt;

&lt;p&gt;The first method, using regular expressions:&lt;/p&gt;

&lt;p&gt;function findNum($str=''){&lt;br&gt;
$str=trim($str);&lt;br&gt;
if(empty($str)){return '';}&lt;br&gt;
$reg='/(\d{3}(.\d+)?)/is';//Regular expression matching numbers&lt;br&gt;
preg_match_all($reg,$str,$result);&lt;br&gt;
if(is_array($result)&amp;amp;&amp;amp;!empty($result)&amp;amp;&amp;amp;!empty($result[1])&amp;amp;&amp;amp;!empty($result[1][0])){&lt;br&gt;
return $result[1][0];&lt;br&gt;
}&lt;br&gt;
return '';&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The second method, using the in_array method:&lt;/p&gt;

&lt;p&gt;function findNum($str=''){&lt;br&gt;
$str=trim($str);&lt;br&gt;
if(empty($str)){return '';}&lt;br&gt;
$temp=array('1','2','3','4','5','6','7','8','9','0');&lt;br&gt;
$result='';&lt;br&gt;
for($i=0;$i&amp;lt;strlen($str);$i++){&lt;br&gt;
if(in_array($str[$i],$temp)){&lt;br&gt;
$result.=$str[$i];&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
return $result;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The third method, using the is_numeric function:&lt;/p&gt;

&lt;p&gt;function findNum($str=''){&lt;br&gt;
$str=trim($str);&lt;br&gt;
if(empty($str)){return '';}&lt;br&gt;
$result='';&lt;br&gt;
for($i=0;$i&amp;lt;strlen($str);$i++){&lt;br&gt;
if(is_numeric($str[$i])){&lt;br&gt;
$result.=$str[$i];&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
return $result;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;E.g:&lt;/p&gt;

&lt;p&gt;//Intercept the number 2 in the string&lt;br&gt;
    $str = 'Q coins 2';&lt;br&gt;
    $result='';&lt;br&gt;
    for($i=0;$i&amp;lt;strlen($str);$i++){&lt;br&gt;
        if(is_numeric($str[$i])){&lt;br&gt;
            $result.=$str[$i];&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
    print_r($result);die;&lt;br&gt;
    // output result 2&lt;/p&gt;

</description>
      <category>php</category>
      <category>html</category>
      <category>webdev</category>
      <category>laravel</category>
    </item>
    <item>
      <title>PHP request interface API: a relatively complete example (POST)</title>
      <dc:creator>leichengde</dc:creator>
      <pubDate>Sun, 03 Jul 2022 07:37:50 +0000</pubDate>
      <link>https://dev.to/leichengde/php-request-interface-api-a-relatively-complete-example-post-3ibg</link>
      <guid>https://dev.to/leichengde/php-request-interface-api-a-relatively-complete-example-post-3ibg</guid>
      <description>&lt;p&gt;1：Send via curl&lt;br&gt;
[Scenario: Get table information in remote server based on id]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
//interface url
$url = '';
//data field
    $data = 'id=35289';
    // method to generate http header information
function getAuthHeaders(){
//appid needs to apply in advance
$appid = '';
$time = time();
//appkey needs to apply in advance
$appkey = '';
//Signature here we use the md5 of the following three
$sign = md5($appid . '&amp;amp;' . $time . $appkey);
return array(
            'Content-Type : application/json',
            'charset : '.'utf-8',
            //We also send the appid, TimeStamp, and signature to the server,
            //Request it to query whether the md5 signature of appkey authentication is correct or not through appid
'X-Auth-Appid : ' . $appid,
'X-Auth-TimeStamp : ' . $time,
'x-Auth-Sign : ' . $sign
        );
}
$ch = curl_init();
//address to visit
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, getAuthHeaders());
//Whether the execution result is returned, 0 is to return, 1 is not to return
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
// Send a regular POST request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// execute and get data
$output = curl_exec($ch);
print_r($output);
    curl_close($ch);
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>php</category>
      <category>api</category>
      <category>html</category>
    </item>
  </channel>
</rss>
