Jump to content

Recommended Posts

Hi,

Im hoping this is a simple one for you guys because its not for me.

 

What im trying to do is automaticlly split a number. So say someone enters into a form 1234567890 I would like to somehow show that number as 1234 567890 as well as 1234567890 but without having to manually edit it.

 

I hope you understand what I am trying to explain.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/179039-solved-split-a-number/
Share on other sites

Thank you so much for the fast reply, sadly that was straight over my head as im very very new to all this. I will however read the link you have provided and attempt to learn this.

 

In the mean time I will explain exactly what im trying to acheive.

 

Im using wordpress so using this code to fetch my title which I want to split. <?p hp the_title(); ?> (I added the space in php in case it does not show)

 

The number is mostly always more than 5.

 

So the code need to fetch the title then split it.

I have found this code. It is editable by me, im ok at edidting things but the one thing I cannot get to work it the start with. I need it to pick up the post title, then convert it for me. I have not edidted this yet but am confident I can do it. All I need help with is how to start with the post title. When I add

<?php the_title(); ?>

which is the wordpress way of doing it, it does not work.

 

<?

$start_with = "MY POST TITLE HERE"; 

$string = preg_replace("![^0-9]!", "", $start_with);

$part1 = substr($string,0,3);
$part2 = substr($string,3,3);
$part3 = substr($string,6,4);

$array = array( "(", $part1, ") ", $part2, "-", $part3);
$phone_num = implode("",$array);

echo $phone_num;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.