Reputation: 1101
Example: 845
, 945
, 1045
, 1145
.
If the length of the string is 3 then I am trying to add a :
after the first character, e.g. 8:45
. If the length of the string is 4 then I am trying to add :
after the second character, e.g. 10:45
. Not sure which method would help me do that. Any suggestions?
while($row = mysqli_fetch_array($result))
{
$message = $row['Timings'];
if(strlen($message) = 3)
{
}
else if(strlen($message) = 4)
{
}
Upvotes: 2
Views: 787
Reputation: 4021
Try this:
$message = substr($message, 0, -2).":".substr($message, -2);
Upvotes: 7