Jump to content

etrader

Members
  • Posts

    315
  • Joined

  • Last visited

    Never

Everything posted by etrader

  1. When the number of words is lesser than the limit defined, it adds "-"s at the end of the string.
  2. I have a string in the form of "word1-word2-word3-word4-word5-word-6-word7", but I want to shorten it to 5 words only.
  3. Thanks for the effective solutions and useful guides
  4. I have a string with the structure of "word(11), word2(43), word3(99)". I want to delete the number between parenthesis to get "word, word2, word3"; but there's something wrong with this: $words = preg_replace("/(0-9)/", "", $words);
  5. You are quite right! It was my stupid mistake, as the problem has come from another issue :-\ Sorry
  6. I want to catch the first word of a string in which the words are separated by "-" (e.g. "first-word-second-one-more"). I used this code: $string = explode('-', $string); echo $string[0]; The problem is that when the string contains only one word, it returns null :-\
  7. Sounds simple! Thanks for solving it!
  8. I have a search box with this code <form method="get" action="/search.php"> <div> <input type="text" value="" name="q" size="30" onclick="this.value='';" /> <input type=submit value='Search' "> </div> </form> and .htaccess of RewriteRule ^search/(.*).html search.php?q=$1 [L] Now, if typing "mysite.com/search/$q.html" it works perfectly as well as "mysite.com/search.php?q=$q"; but my problem is that 1. I expect redirecting to "mysite.com/search/$q.html" when typing "mysite.com/search.php?q=$q" (I mean on the browser url place). 2. More importantly, when searching something in the search box, it sends to "mysite.com/search.php?q=$q", but not "mysite.com/search/$q.html" :-\
  9. How can I replace ' and " with str_replace? When I using the following code, I will get error. $string = str_replace(""", "something", $string);
  10. Oh, Thanks! with new SimpleXMLElement; I got it
  11. Yes, it is xml but somehow different. How can I turn it into array? when doing $xml = simplexml_load_file("http://www.gigablast.com/search?q=korn&raw=9"); print_r($xml); The result is SimpleXMLElement Object ( [hits] => 1033508 [moreResultsFollow] => 1 [result] => Array ( [0] => SimpleXMLElement Object ( [title] => SimpleXMLElement Object ( ) [sum] => SimpleXMLElement Object ( ) [url] => ... As you see, instead of actual words of title it shows "[title] => SimpleXMLElement Object ( )"
  12. According to the instruction provided by in http://www.gigablast.com/searchfeed.html#output gigablast provides a normal xml which can be read as <response> <result> <title> </title> </result> </response> but when checking an example xml page like http://www.gigablast.com/search?q=korn&raw=9, it is a text file without attributes, and I was unable to read it as array by simplexml_load_file. :-\
  13. WOW! very simply and handy Thanks!!!
  14. This is a brilliant solution, but it has a big problem: it does not work with line breaks. If even writing the php code in two lines as $subject = "I want everything before tim and nothing after"; $pattern = '/.* tim/'; preg_match($pattern, $subject, $matches); print_r($matches); The result will be "before tim" not "I want everything before tim"
  15. $subject is a string, and this turns it to an array ($matches), am I wight? I need to change the array to string again to display with echo?
  16. Thanks Pikachu2000! This is exactly what I meant: simple and effective Thanks a million!
  17. Actually, I need to split the string to two new ones, as I can handle both of them (Yes, I need both of them). The solution provided by JakeTheSnake3.0 was very simple and thus attracted my attention; however, it only works for the first part (returning the string before the last "-").
  18. There are many ways to delete everything after a character in a string. I am looking for a simple way to delete everything after a given word.
  19. It works well; but a question out of curiosity. What is the role of unset? Yes, we deal with the last "-"; it may happen several times.
  20. I have a $string with this structure "word-word2 something-SECONDPART". I want to divide it to $string1 and $string2 by separating with the last "-". The point is that "-" exists in the first part, and I just want to make the second string after the last "-"
  21. Sorry, I got a little bit confused. Could you please provide an example code doing this?
  22. I get strings via simplexml with this code $xml = simplexml_load_file("test.xml"); foreach ($xml->title->case as $value){ $param1 = $value->param1; $param2 = $value->param2; Now I want to randomize the xml items (not in their original order); but I cannot use shuffle($value); because it does not consider $value as an array. How can I make a random order?
  23. if (!empty($test_array)) worked THANKS
  24. You mean if (!empty($test_array)) { echo "nothing to display"; } else { running the main code}
  25. I have an array which can be empty; in this case, I get error. I want to skip when the array is empty. When calling the array from file, I use the following code if (file_exists($array_file)) { "the doing code" } else { echo "File does not exist"; } How I should use this If Else condition when array comes from a string like $test_array = explode(', ', $examplestring, -1);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.