Bitcoin Forum
May 11, 2024, 07:56:08 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: finding Bitcoin address in a MYSQL text column  (Read 1447 times)
gatomalo (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile WWW
March 11, 2015, 12:50:47 AM
 #1

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   
1715414168
Hero Member
*
Offline Offline

Posts: 1715414168

View Profile Personal Message (Offline)

Ignore
1715414168
Reply with quote  #2

1715414168
Report to moderator
1715414168
Hero Member
*
Offline Offline

Posts: 1715414168

View Profile Personal Message (Offline)

Ignore
1715414168
Reply with quote  #2

1715414168
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
March 11, 2015, 12:57:53 AM
 #2

Remove the ^ and $

paradoxal420
Full Member
***
Offline Offline

Activity: 229
Merit: 100


View Profile
March 11, 2015, 01:20:46 AM
 #3

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}/

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
PRIMEDICE
The Premier Bitcoin Gambling Experience - PRIMEDICE 3 HAS LAUNCHED @PrimeDice
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
gatomalo (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile WWW
March 11, 2015, 03:26:39 PM
 #4

Thanks that worked great  Wink

<?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";
}
?>
idsocho
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
March 13, 2015, 11:00:18 AM
Last edit: March 28, 2015, 07:32:53 AM by idsocho
 #5

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
emrebey
Sr. Member
****
Offline Offline

Activity: 476
Merit: 250


View Profile
March 14, 2015, 07:17:49 PM
 #6

preg_match have a parameter to store the results.
http://php.net/manual/en/function.preg-match.php

see $matches.
nuno12345
Sr. Member
****
Offline Offline

Activity: 276
Merit: 284


View Profile
March 17, 2015, 02:11:31 PM
 #7

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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!