let output string will be,

str="01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010"

Some manipulation, *******

Resultant string should be,

"01/Mar/2010,02/Mar/2010<br/>03/Mar/2010,04/Mar/2010<br/>05/Mar/2010"

Here I want to replace Comma (,) by <br/>

Note:

I want to replace even commas only. (before 03/mar/2010 & 05/Mar/2010..like)

<?php
$string="your string";
$arr=explode(",",$string)
$newstr="";
$total=count($arr);
for($i=0;$i<$total;$i++)
{
    $newstr.=$arr[$i];
    if($i%2==0)
       $newstr.="<br/>";
    elseif($i<($total-1));
       $newstr.=",";
}
echo $string;
echo $newstr;
?>

let output string will be,

str="01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010"

Some manipulation, *******

Resultant string should be,

"01/Mar/2010,02/Mar/2010<br/>03/Mar/2010,04/Mar/2010<br/>05/Mar/2010"

Here I want to replace Comma (,) by <br/>

Note:

I want to replace even commas only. (before 03/mar/2010 & 05/Mar/2010..like)

just simple,
select Replace('01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010', ',','<br />')

just simple,
select Replace('01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010', ',','<br />')

I believe he said a <br/> every 2 tokens. The code you posted places it after every token. He's something I quickly whipped up.

DECLARE @dateList AS VARCHAR(1000)
DECLARE @dataItem AS VARCHAR(255)
DECLARE @newList AS VARCHAR(1000)

DECLARE @token AS INT
DECLARE @count AS INT

SELECT @dateList = '01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010',
       @dateList = @dateList + ',',
       @count    = 0,
       @newList  = ''

WHILE PATINDEX('%,%', @dateList) <> 0
BEGIN
  
  SELECT  @token = PATINDEX('%,%', @dateList),
          @dataItem = LEFT(@dateList, @token - 1),
          @dateList = STUFF(@dateList, 1, @token, null)

  IF ( @count % 2 ) = 0 AND @count > 0
  BEGIN
    SET @newList = LEFT( @newList, DATALENGTH( @newList ) - 1 ) + '<br/>'
  END  

  SET @count = @count + 1  
  SET @newList = @newList + @dataItem + ',' 
END


PRINT LEFT( @newList, DATALENGTH( @newList ) - 1 )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.