Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:54:25+00:00 2026-06-15T05:54:25+00:00

code: $str = ‘test2$test2$test3$test3$test4’; $id = ‘test2’; We need to find the value of

  • 0

code:

$str = 'test2$test2$test3$test3$test4';
$id = 'test2';

We need to find the value of $id and remove $test2 or test2$ depending on the position test2 in the string ;

To search using:

$substr_count1 = substr_count ($str, '$test2');
$substr_count2 = substr_count ($str, 'test2$');
if ($substr_count1> 0) {
//if exist $test2 then need delete single value $test2 from row and row will be
// $str = 'test2$test3$test3$test4'
// find the value of $test2
// how to remote one value $test2
}
elseif ($substr_count2> 0) {
//if exist test2$ then need delete single value test2$ from row and row will be
// $str = 'test2$test3$test3$test4'
// find the value of test2$
// how to remote one value test2$
}

how to remove a single value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:54:27+00:00Added an answer on June 15, 2026 at 5:54 am

    You need to replace the first occurence of the ‘$test2’ if exists, if not, replace the first occurence of ‘test$’:

    $str = 'test2$test2$test3$test3$test4';
    $id = 'test2';
    
    $position1=strpos($str,'$'.$id);
    $position2=strpos($str,$id.'$');
    
    //if the first occurence is the '$test2':
    if($position1<$position2)
    {
    $str= preg_replace('/'.'\$'.$id.'/', '', $str, 1);
    }
    //If the first occurence is the 'test$'
    else
    {
    $str= preg_replace('/'.$id.'\$'.'/', '', $str, 1);
    }
    
    echo $str;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code Dim str As String = str1,str2 Dim array() As String
Here is the code: string str; cin>>str; cout<<first input:<<str<<endl; getline(cin, str); cout<<line input:<<str<<endl; The
i have an error in this code NSString *str = @above string; //load above
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Here is the current code in my application: String[] ids = str.split("/"); When profiling
my code var str =$(this).attr('id'); this will give me value == myid 5 var
I have next JS-code: var str = 'some string'; var rexp = /^([^#]+)/; var
i have a problem in string manipulation here is the code string str =
I have for example the following piece of code: string str; int i; cout<<input:;
I have this code: string Str = <String><MoreString>; int Start = Str.LastIndexOf('<') + 1;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.