0

Assuming this is a host issue, but I don't see how it could be reading wrong (works perfectly on locahost)

I an returning an array called $result, for this instance of the loop, $v is a telephone number

$k = 'phone'; $v = '(555) 555-1212)';

I have tried

$result[$k] = preg_replace('/(\W*)/', '', $v);

I have also tried

$result[$k] = preg_replace('/[^0-9]/', '', $v);

I have received values for $v of anything from -198040413 to 1260583916 expected result would be 5555551212

echoing results to page for both cases gives expected result, so its not a preg_repalce issue, must be db issue

I know this is not an int limit issue, I am using a varchar(10) for testing the problem

host is Arvixe.com using PHP 5.3.27, I have had other conflicts with them, but preg_replace should be pretty straight forward code (you would think)

6
  • 1
    Try to check echo preg_replace('/\D+/', '', $v); first. Commented Oct 6, 2013 at 16:35
  • 1
    You need to reduce the scope of the problem. Try to echo it first without saving it to the database. If it doesn't work as expected you could safely say that the database is ok and that the problem is somewhere else. Now, I can't really see what's the problem. You didn't give the expected results and what you actually are getting. Also the thing about int: preg_replace() doesn't return an int, it returns a string. Basically I think you're mixing up things Commented Oct 6, 2013 at 16:36
  • updated with expected result, 10 digit number only Commented Oct 6, 2013 at 16:38
  • 1
    @Kender how are you inserting them ? Also what's the encoding of your column ? It might be an encoding issue ... Commented Oct 6, 2013 at 16:48
  • 1
    resolution below, thanks @HamZa for pointing me in the right direction Commented Oct 6, 2013 at 16:51

1 Answer 1

1

Found the issue, it was with the insert

I was inserting into a varchar using i as type, changing it to s as type fixed it

// does not work
bind_param('i', $phone);

// does work
bind_param('s', $phone);

when inserting into a varchar field

Sign up to request clarification or add additional context in comments.

2 Comments

Great. Remember i is used when the corresponding variable has type integer and s is used when the corresponding variable has type string. For more information, go to: php.net/manual/en/mysqli-stmt.bind-param.php
my only question is... why would a varchar insert alter the input data even if it is a totally numeric value? would the solution been as easy as wrapping the insert in quotes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.