Author

Topic: finding Bitcoin address in a MYSQL text column (Read 1467 times)

sr. member
Activity: 276
Merit: 284
If you have spaces as separators in the field you can use this method:
Include https://github.com/LinusU/php-bitcoin-address-validator

Code:
   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
sr. member
Activity: 476
Merit: 250
preg_match have a parameter to store the results.
http://php.net/manual/en/function.preg-match.php

see $matches.
newbie
Activity: 1
Merit: 0
so how do I extract thee address form this field? - Thanks  
















____________________________________________________________________

We are the pioneers in learnalanguage - learn dutch dumps and  tutorials with learnalanguage - learn japanese exam pass guarantee. Download our latest test king ccie Babbel questions to pass real exam of mcitp training in Learnamericanenglishonline
newbie
Activity: 14
Merit: 0
Thanks that worked great  Wink


$test1 = "1DhSiBeYD4JNZvim4EefnEoFV2WMFc7e5d";

$test2 = "xxx 1DhSiBeYD4JNZvim4EefnEoFV2WMFc7e5dabcd  xxxx";



if (preg_match("/[13][a-km-zA-HJ-NP-Z0-9]{26,33}/", $test2, $matches))
{
  echo "

Bitcoin Address found Match was found

";
  echo $matches[0];
}else {
  echo "No Btcoin address found";
}
?>
full member
Activity: 229
Merit: 100
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?

 Huh $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}/
sr. member
Activity: 467
Merit: 267
Remove the ^ and $
newbie
Activity: 14
Merit: 0
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?

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

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