Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: gatomalo on March 11, 2015, 12:50:47 AM



Title: finding Bitcoin address in a MYSQL text column
Post by: gatomalo on March 11, 2015, 12:50:47 AM
I have a string of data in my mysql database column - I am using PHP - I want to search my db in a column and see if there are any Bitcoin addresses in the field. -

$test1 "1Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
preg_match("/^[13][a-km-zA-HJ-NP-Z0-9]{25,34}$/", $test2, $matches)
This works if the address is at the beginning - how about if it somewhere else in the field?

 ??? $test1 = "my bit coin address is 1Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx can you help me";

so how do I extract thee address form this field? - Thanks   


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: hhanh00 on March 11, 2015, 12:57:53 AM
Remove the ^ and $


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: paradoxal420 on March 11, 2015, 01:20:46 AM
I have a string of data in my mysql database column - I am using PHP - I want to search my db in a column and see if there are any Bitcoin addresses in the field. -

$test1 "1Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
preg_match("/^[13][a-km-zA-HJ-NP-Z0-9]{25,34}$/", $test2, $matches)
This works if the address is at the beginning - how about if it somewhere else in the field?

 ??? $test1 = "my bit coin address is 1Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx can you help me";

so how do I extract thee address form this field? - Thanks  

Try this instead:

Code:
/[13][a-km-zA-HJ-NP-Z0-9]{26,33}/


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: gatomalo on March 11, 2015, 03:26:39 PM
Thanks that worked great  ;)

<?php

$test1 = "1DhSiBeYD4JNZvim4EefnEoFV2WMFc7e5d";

$test2 = "xxx 1DhSiBeYD4JNZvim4EefnEoFV2WMFc7e5dabcd  xxxx";



if (preg_match("/[13][a-km-zA-HJ-NP-Z0-9]{26,33}/", $test2, $matches))
{
  echo "<br><br>Bitcoin Address found Match was found <br><br>";
  echo $matches[0];
}else {
  echo "No Btcoin address found";
}
?>


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: idsocho on March 13, 2015, 11:00:18 AM
so how do I extract thee address form this field? - Thanks  
















____________________________________________________________________

We are the pioneers in learnalanguage - learn dutch (http://www.learnalanguage.com/learn-dutch/) dumps and  tutorials with learnalanguage - learn japanese (http://www.learnalanguage.com/learn-japanese/) exam pass guarantee. Download our latest test king ccie Babbel (http://www.babbel.com/) questions to pass real exam of mcitp training in Learnamericanenglishonline (http://www.learnamericanenglishonline.com/)


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: emrebey on March 14, 2015, 07:17:49 PM
preg_match have a parameter to store the results.
http://php.net/manual/en/function.preg-match.php

see $matches.


Title: Re: finding Bitcoin address in a MYSQL text column
Post by: nuno12345 on March 17, 2015, 02:11:31 PM
If you have spaces as separators in the field you can use this method:
Include https://github.com/LinusU/php-bitcoin-address-validator

Code:
<?php
   
use \LinusU\Bitcoin\AddressValidator;
   
$addrVersion "00";
   
$string "my bit coin address is 1Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx can you help me";

   
$parsed explode(" "$string);

   foreach(
$parsed as $row)
   {
       
$ret AddressValidator::isValid($row$addrVersion);

       if(
$ret) echo $row " is valid";
   }
?>

By changing $addrVersion you can make it work with any coin out there.

Hope this helps