从字符串名称仅打印月份名称和年份

时间:2015-09-08 06:16:04

标签: php

Iam的字符串名称与" 2015年6月OLD"。我想仅打印一个月和一年,我的意思是o / p喜欢

2015年6月

根据我的任务,仅在年后才会添加额外名称。是否可以在年后删除文本名称,或者只从该给定的字符串名称中删除月份和年份。

先谢谢

2 个答案:

答案 0 :(得分:1)

$str  = "JUNE 2012 OLD"; //random string 
$strArr = explode(" ", $str); //split string based on space
if(count($strArr)>=2 && $strArr[1]!='' ) //check if array is of length 2 or more
    echo $strArr[0]." ".$strArr[1]; //print the first and second part of array which is month and year
else //invalid string because it does't have month and year
    echo "Do anything else string does't have month and year"

答案 1 :(得分:0)

这应该对你有用

for each companyid and for each state in that companyid in csv file:
     list1 = 12 records from the csv file
     list2 = 12 records from the dictionary after mapping the abbreviated state through the state dictionary that I have
     call func1(list1,list2)