0

I have an game ip in my database, like so: "271.29.248.23:27912"

I want the substring to take the last 5 numbers "27912" and also i want to delete the ":". Is that possible and could someone help me?

And if possible i would like the numbers to be like this so it would be easier...

$ip = "271.29.248.23";
$port = "27912";

Please help me, i need this for a script :(

2 Answers 2

5
 list($ip, $port) = explode(":", "$your_string:");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the fast reply, i will test it out :)
$your_string . ':' would be cleaner.
2

You could also use parse_url, which will handle more cases:

$url = "271.29.248.23:27912";
print_r(parse_url($url));

Prints:

Array
(
    [host] => 271.29.248.23
    [port] => 27912
)

Comments

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.