0

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);

Edited by Dani: Formatting fixed

3
Contributors
8
Replies
32
Views
4 Years
Discussion Span
Last Post by HasNor
0

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

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

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..

0

Have you tried removing the semicolon?

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

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 ';' -->','

0

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.

0

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

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.