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
0
votes
5 answers

php only get the first occurrence of a word from an array

I have an array of tags that I'm pulling from a database, I am exporting the tags out into a tag cloud. I'm stuck on getting only the first instance of the word. For example: $string = "test,test,tag,tag2,tag3"; $getTags = explode("," , $string); …
Brooke.
  • 3,691
  • 13
  • 49
  • 80
0
votes
1 answer

Should I use strstr() to loosely validate urls before passing them to preg_match()?

I am writing a function to parse some videosites urls in order to generate embedding html: if (strstr($url, 'a.com')) { $from = 'a'; } elseif (strstr($url, 'b.com')) { $from = 'b'; } else { return 'Wrong Video Url!'; } if ($from == 'a')…
samluthebrave
  • 163
  • 1
  • 7
0
votes
2 answers

strstr not able to search the string inside the data in octal format

I am trying to find a string in the given file (actually the file is tar file(please pay attention here) and i opened the file in notepad++ and took randomly a string from that opened file) and i stored that full tar file in a buffer and now i want…
Sss
  • 1,519
  • 8
  • 37
  • 67
0
votes
4 answers

Find formatted string

I'm interested in something like strstr() function but that I could pass a formatted string as argument, like what I pass to printf(). To be clear, let's get an example: Suppose that I want to find this text: "abc:123" where abc could be any string…
Leandro Lima
  • 1,140
  • 3
  • 24
  • 42
0
votes
3 answers

strstr() to search two different strings in the same line

I am trying to search two different strings in a line using strstr. sBuffer = "This is app test" s1= strstr (sBuffer, "This"); s2= strstr (sBuffer, "test"); printf("%s\n", s1); //prints - This is app test printf("%s\n", s2); //prints - test if (s1…
user32262
  • 8,660
  • 21
  • 64
  • 77
0
votes
1 answer

Database in .txt file?

I'm making a program that emulates a ATM, so I want to save the account data in a .txt file, and then if the user wants to see the balance of his account search for the balance associated to his account number. To accomplish this I was thinking to…
0
votes
2 answers

Looping through an array for strings and putting the found strings into another array

Im trying to loop through the $files array and: Find occurrences of "some-string". For every "some-string" occurrence found, i need to add it to an array. (ie. $some_strings). Finally be able to call $some_string array outside of the for loop for…
codename32
  • 171
  • 1
  • 9
0
votes
2 answers

Match exactly with strstr

How can I use strstr to match the content of a variable exactly instead of just containing? For example: www.example.com/greenapples www.example.com/redapples www.example.com/greenapplesandpears If my URL is set as a variable $myurl and I use the…
fightstarr20
  • 11,682
  • 40
  • 154
  • 278
0
votes
2 answers

Search a string with strstr in a part of an char *

currently I search a char * with strstr but I dont want to search in the complete one, only from the 42. char to the end. How can I achieve this?
Sebastian
  • 952
  • 1
  • 14
  • 41
0
votes
1 answer

How do I find more than one occurence and replace using str?

My homework assignment is to read a file, store in target words (delimited by #) and replacement words (also delimited by #) and original strings (they do not have #). Also I could not assume max str length, or max # of words. For example: #uic#e#…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
0
votes
1 answer

Target str_replace() to work on only one element in wp-admin

Is it possible to use PHP's str_replace() function to target only select DIV's within a page (identified by ID or classes for example)? The situation: I'm using the following str_replace() function to convert all checkboxes in my Wordpress Post…
Paul Thomson
  • 105
  • 2
  • 11
0
votes
1 answer

Using strstr() to exclude values in excel while not shifting cells up

I am working in PHP using strstr() to remove values which are extracted from a MYSQL db to be outputted to an excel file- CODE: If (!strstr($value, ' Ive tried these two code snippets without…
Merica
  • 129
  • 1
  • 11
0
votes
3 answers

How to get string before char?

echo $_SERVER['REQUEST_URI']."\n"; echo strrchr($_SERVER['REQUEST_URI'], '/'); strrchr returns the same adress as it was before, but i need all until last /. Update: $_SERVER['REQUEST_URI'] = /users/dev/index.php i need /users/dev/
user1692333
  • 2,461
  • 5
  • 32
  • 64
0
votes
2 answers

read from a file c code

I have the following code to read from a file: fin = fopen("file1.txt", "r"); char* url; if ( fin ) { while ( line = read_line(fin) ) { if ( (url=strstr(line, "url="))!=NULL ) { fprintf(stdout, "%s \n", url); …
just ME
  • 1,817
  • 6
  • 32
  • 53