Dear experties,
I have a problem to remove semicolon at last value, but not working. This script working if I change the ';' to comma ','.. What is the problem actually?

Please help me..

> if(isset($sw11))
  $symp39=$sw11.";";
  else
 $symp39=NULL;

if(isset($sap_rel))
  $symp40=$sap_rel."";
  else
  $symp40=NULL;

if(isset($subject))
  $symp41=$subject.";";
  else
  $symp41=NULL;

if(isset($module))
  $symp42=$module."";
  else
  $symp42=NULL;

$subcat = $symp39."".$symp40."".$symp41."".$symp42;
$sub = preg_replace('/,[^,]*;$/', '', $subcat);

Recommended Answers

All 8 Replies

When i run this statement, it works fine for me. What does the error say?

$sw11 = "hi";
$symp39=$sw11.";";
echo $symp39;

Thanks for reply fobos,
actually,no error message I got..
but data show still have ';' at the end of the value.
if I change to comma, there will show without ',' at the end of the value..
That's the problem..

Have you tried removing the semicolon?

$sw11 = "hi";
$symp39=$sw11;
echo $symp39;

tested. but database shown value not separated..
before removed the ';' I got
1;3;5;7;
after removed the ';' I got
1357
what I want is
---- > 1;3;5;7
if I change the semicolon to comma I got
1,3,5,7

why it's working for comma but not working for semicolon? I didn't change any only ';' -->','

you should have said that in the beginning

what I want is
---- > 1;3;5;7

So you will probably have to do something like this

if(isset($sw11)) {
$symp39=$sw11;
}  else {
 $symp39=NULL;
}

if(isset($sap_rel)) {
    if($symp39 = NULL) {
        $symp40 = $sap_rel;
    } else {
        $symp40 = symp39.”;”.$sap_rel;
    }
} else {
    $symp40=NULL;
}

Or just make the first isset "$sw11" a required field and put the semicolons on the rest of the variable in front, so this way the first will always show with no semicolon, and the rest -- weather NULL or not -- will have a semi colon in front of it.

---> 1
---> 1;3
---> 1;5
---> 1;3;5

and so forth.

remove the last character from a string
$data = substr($data,0,(strlen($data)-1));

thanks moneeshot, i've tried with
$sub = substr($subcat,0,(strlen($subcat)-1));

still does't work..
:( help me..

when I search in google, most of them not using ';'
is it not suitable to use as separate characters??

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.