tags:

views:

50

answers:

5

Hi

Am insert the group of string into my table,

this is sample one

|=|4|=|3|=|5|=|3|=|Yes|=|No comments .

Some time my string may like this manner

|=|4|=|3|=|5|=|3|=|Yes|=|

For this situation i want to append this string (Sorry no data) at the end of |=| this symbol ,

Also my string may like

 |=|4|=|3|=|5|=|3|=|Yes|=| 

That is symbol end is empty space ,in this situation also i want to append this string (Sorry no data) at the end of |=| this symbol ,,

Can u tell me how to do this ?

Thanks

+1  A: 

the question is... why do you need to do this? for me, is sounds like your the structure of your database is wrong and you are trying to save n varibles into 1 field (if i'm right, take a look at this, if i'm wrong i missunderstood your question...).

oezi
+1  A: 

Use susbstr to extract end of string

if (substr($string, -3) == '|=|') 
    $string .= '(Sorry no data)';

Or with one space character

if (substr($string, -1) == ' ') 
        $string .= '(Sorry no data)';

You can also achieve same thing with regular expressions

Benoit
+1  A: 

Try this:

$splitted = explode("|=|", $your_string);
if (count($splitted) < 6)
{
  $your_string .= "Sorry no data";
}

If you want to add "Sorry no data" also if the last section is "No comments", change the if to:

if (count($splitted) < 6) || $splitted[5] == "No comments")
Tobias
A: 

$string = "|=|4|=|3|=|5|=|3|=|Yes|=|";

$var = explode("|=|",$string);

$pick_last_array = count($var);

$pick_last_array = $pick_last_array-1;

if(trim($var[$pick_last_array])==""){

$my_last_val = "Am coming";

}else{

$my_last_val = $var[$pick_last_array];

}

echo $my_last_val;

This snippet fixed my problem

thanks to all

This

Bharanikumar
A: 

**$string = "|=|4|=|3|=|5|=|3|=|Yes|=|";

$var = explode("|=|",$string);

$pick_last_array = count($var);

$pick_last_array = $pick_last_array-1;

if(trim($var[$pick_last_array])==""){

$my_last_val = "Am coming";

}else{

$my_last_val = $var[$pick_last_array];

}

echo $my_last_val; **

antonio