Questions tagged [strstr]

A function that searches a string in another string.

A function that searches a string in another string.

Examples

php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

(Example taken from php.net)

Resources

363 questions
-1
votes
1 answer

string returned from strstr function is not the same as the the string

So I had this program. It should print out true since ret is "Point", just that I got it from strstr, and I am comparing it to the string "Point". For some mysterious reason, they are not the same strings. What is going on? Here is the…
-1
votes
1 answer

How to make strstr efficient so that it does not catch unwanted substrings

For example, if the string is "Only for Geeky People" and I am looking for only "Geek" substring not "Geeky", it would say the word is not present. ie strstr("Only for Geeky People", "Geek") would be NULL. How do I address such an issue?
-1
votes
1 answer

What is the complexity of strstr in c?

What is the complexity of strstr in c? I have looked for the answer to the problem for a long time, but still cannot find it.
-1
votes
1 answer

remove before specific string not character

Format of string is as follow $img = "/images/posts/main.jpg"; $img1 = "/images/posts/john.jpg"; I need to remove /images/posts/ and echo rest of the content. I tried with strstr, But I found it deals with only character echo strstr($img,…
AnandaLC
  • 43
  • 1
  • 9
-1
votes
1 answer

How to split string using pattern matching?

I have a string like "123-#-#-abc-user-#-#-abcpassword-#-#-123456", i need to split this string with pattern "-#-#-" to create an array. I used the following code to do this char buf[5000]; strcpy(buf,…
Dev
  • 69
  • 8
-1
votes
2 answers

Why does fopen() not recognize my file's name?

The programm should be able to open a file like myFile.txt, alltough it's real name is myFile without the extension .txt. So I wrote the function called removeFileExtension() in order to achieve that. It does open my file by copying the string from…
PatrickSteiner
  • 495
  • 4
  • 26
-1
votes
4 answers

How to use strtok to get a word

I'm having some problem with my code. I need to use strtok() in c to output the words "Sing" and "Toy" (which are both in between the words "Due" and "De") in the string "Date WEEk Dae Due Toy De Dae i Date Due Sing De". I tried to use the if…
Antonio
  • 1
  • 2
-1
votes
1 answer

strstr - Not working correctly with XML Response (Symbols)

Edited post requested by Michael. $Response = $soapClient->__getLastResponse(); $pos = strpos($Response, ">"); echo substr($Response, $pos+1); // Returns soap:ReceiverServer was unable to process request. ---> Product already exists $Response =…
Jake
  • 141
  • 3
  • 12
-1
votes
3 answers

Check if a string is in a file

I've been trying to make a program that checks if a file contains another file's. (like an anti Virus). I tried to use strstr() to do so but apparently the strstr() does not work so well. What is the best solution to check if a file contains another…
-1
votes
1 answer

C strstr not working correctly

I am trying to use strstr to search for any matches using a substring and comparing it to a line of text but haven't been successful in getting a match so far. I am opening and reading a file using popen while trying to do a search with only the…
user1610834
  • 115
  • 2
  • 13
-1
votes
1 answer

strstr() in friend array not working

I have this code, which takes data from MySQL of two users. And when i click on "remove" button it will erase the user from both friend array and results return back into database. But it doesn't work. Help me, please. if (@$_POST['removefriend'])…
Jan Radosta
  • 147
  • 1
  • 10
-1
votes
1 answer

STR Function [PHP]

Well guys, I'm here because I want to do something advanced on my site, and I don't know how do this and if is possible do this. It's like this: Someone will register on my site and have an function to verify if this name is blocked or not in…
-1
votes
2 answers

checking a char pointer for NULL in strstr

I was trying to implement strstr in C but I was stuck at this piece of code which was crashing at runtime while (*a==*b && a != NULL && b != NULL) { a++ b++ } if (b == NULL || *b == '\0') { // string found } After googling for sometime I…
user1781626
-1
votes
1 answer

passing argument 2 of ‘strstr’ makes pointer from integer without a cast?

what does this warning mean? I read some other posts about a similar question, but I'm still not understanding how to go about solving it. # define EOT_CHAR '\04' char buffer[MAXLINE]; if ( strstr( buffer, EOT_CHAR ) != NULL ) …
PetitPlaid
  • 91
  • 3
  • 8
-1
votes
1 answer

Store every substring from a string in an array

Im new here so excuse me if I miss anything. I'll go straight to the point. I want to read a .txt file and store all the words inside an array of words, so what Im doing is this: int countWords(char *stringInput) { char const *p = stringInput; int…
Dro
  • 17
  • 5