etrader
Members-
Posts
315 -
Joined
-
Last visited
Never
Everything posted by etrader
-
limiting the string length by the number of words
etrader replied to etrader's topic in PHP Coding Help
When the number of words is lesser than the limit defined, it adds "-"s at the end of the string. -
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.
-
Thanks for the effective solutions and useful guides
-
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);
-
You are quite right! It was my stupid mistake, as the problem has come from another issue :-\ Sorry
-
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 :-\
-
Sounds simple! Thanks for solving it!
-
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" :-\
-
How can I replace ' and " with str_replace? When I using the following code, I will get error. $string = str_replace(""", "something", $string);
-
Oh, Thanks! with new SimpleXMLElement; I got it
-
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 ( )"
-
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. :-\
-
WOW! very simply and handy Thanks!!!
-
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"
-
$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?
-
Thanks Pikachu2000! This is exactly what I meant: simple and effective Thanks a million!
-
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 "-").
-
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.
-
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.
-
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 "-"
-
Sorry, I got a little bit confused. Could you please provide an example code doing this?
-
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?
-
if (!empty($test_array)) worked THANKS
-
You mean if (!empty($test_array)) { echo "nothing to display"; } else { running the main code}
-
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);