Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify string, PHP

Tags:

string

php

I have a string, for example

20120201

I need to change it to

2012/02/01

obviously I need to add "/" after the 4th, 6th characters in the string.

Could someone help me do this in PHP?

Thank you.

like image 490
user1233852 Avatar asked Dec 17 '22 03:12

user1233852


1 Answers

Something like this:

$final = substr($initial,0,4).'/'.substr($initial,4,2).'/'.substr($initial,6,2)

Use substr.

like image 52
Narek Avatar answered Jan 01 '23 08:01

Narek