PHP - Search String For Characters
Hi, I am trying to search a string for a string of characters in this order ../ and carry out relevant if statements but it returns the same result every time. On echoing my $pos, $pos2, $pos3 and $pos4 variables the first two come back 0 and they are the strings that do contain ../ but the if statements perform the same? I don't understand, any ideas? Thanks...
Code: [Select] <?php $logo = $info ['logo']; $pos = strpos($logo, "../");//check if image contains ../ if ($pos == 0) {} else { $logo = substr($logo, 3);} $image1 = $info ['image1']; $pos1 = strpos($image1, "../");//check if image contains ../ if ($pos1 == 0) {} else { $image1 = substr($image1, 3);} $image2 = $info ['image2']; $pos2 = strpos($image2, "../");//check if image contains ../ if ($pos2 == 0) {} else { $image2 = substr($image2, 3);} $image3 = $info ['image3']; $pos3 = strpos($image3, "../"); //check if image contains ../ if ($pos3 == 0) {} else { $image3 = substr($image3, 3);} ?> Similar TutorialsDoes anybody know of a function or a way of letting me get the string between whatever characters? Say I had [SOMEWORD] text [SOMEWORD] then how could I go about getting the value "text", please note I'm not trying to make bbcode or similar. Hello Everyone, I am working on a project I pull the field names from the database. I am trying to remove the underscore (_) when the field name is displayed. Does anyone know how I would do that? Here is the code that I am working with Code: [Select] $i = 0; while ($i < mysql_num_fields($fieldnamesquery_result)) { $meta = mysql_fetch_field($fieldnamesquery_result, $i); if (!$meta) { echo "No information available"; } $meta = str_replace("_", " ", $meta); $tablecolumn .= "<p>" . $meta->name . ":<input type='text' name='" . $meta->name . "' id='" . $meta->name . "' /></p>"; $i++; How I can explode by a series of characters (not one single character)? For example, divide the string to an array by any of these characters "," and ";" and "." $string = "this, that;some.word;second"; I want to put all of these words into an array. Am looking forward to removing all the numeric characters upto and including the leading "/" in 90/_featuredarticles/2011/12 Regards This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320682.0 I have a large amount of text, (text can be different at any time), I count the number of characters in the string,and divide it by 2 so that half of the text will be in one variable, the other half in the other, however I am not sure how to get the split function, or whichever function to split it by the number of characters. example: $text = "lorem ispum dolar sit amet, consecterur adiscing elit. Donec dictum placerat sapien, in eliefend liber"; $cut = strlen($text)/2; //(here's where i cannot get it to work/do not know which function to use and how to use it) //but what I want it to do is to split it half way. I want to allow Alphabetical strings, Numeric strings, and Alphanumeric strings. For example "Bob", "1234", "bob1234" are all valid. I want to check if the string has invalid characters, return true if it does (or false, which ever method works). How can I do it? Hi, Im looking at using a statement like this to remove all text characters from a string. $outgoing = substr_replace($incoming,"",-1); The string is a currency that has a currency symbol in the beginning of the string, like "R500.00" I would like to remove the R, so it is just a numeric value... Please can you help me with any ideas on how to get this going? Been reading so much and its all confused me too badly. Regards, Chris Hi I am trying to replace characters in a string with images so character 'a' will be replaced with a.jpg etc I have tried the following code but that doesn't result in the desired effect as the updated string gets it's characters replaced as the script works through it so the 'img' in the first updated string gets replaced with with images and it all ends up quite a mess. Is there a simpler way to do this? $content = "abc" ; $content = str_replace("a", "<img src=images/a.jpg >", $content); $content = str_replace("b", "<img src=images/b.jpg >", $content); $content = str_replace("c", "<img src=images/c.jpg >", $content); $content = str_replace("d", "<img src=images/d.jpg >", $content); $content = str_replace("e", "<img src=images/e.jpg >", $content); $content = str_replace("f", "<img src=images/f.jpg >", $content); $content = str_replace("g", "<img src=images/g.jpg >", $content); $content = str_replace("h", "<img src=images/h.jpg >", $content); $content = str_replace("i", "<img src=images/i.jpg >", $content); $content = str_replace("j", "<img src=images/j.jpg >", $content); $content = str_replace("k", "<img src=images/k.jpg >", $content); $content = str_replace("l", "<img src=images/l.jpg >", $content); $content = str_replace("m", "<img src=images/m.jpg >", $content); $content = str_replace("n", "<img src=images/n.jpg >", $content); $content = str_replace("o", "<img src=images/o.jpg >", $content); $content = str_replace("p", "<img src=images/p.jpg >", $content); $content = str_replace("q", "<img src=images/q.jpg >", $content); $content = str_replace("r", "<img src=images/r.jpg >", $content); $content = str_replace("s", "<img src=images/s.jpg >", $content); $content = str_replace("t", "<img src=images/t.jpg >", $content); $content = str_replace("u", "<img src=images/u.jpg >", $content); $content = str_replace("v", "<img src=images/v.jpg >", $content); $content = str_replace("w", "<img src=images/w.jpg >", $content); $content = str_replace("x", "<img src=images/x.jpg >", $content); $content = str_replace("y", "<img src=images/y.jpg >", $content); $content = str_replace("z", "<img src=images/z.jpg >", $content); echo $content ; Any help would be gratefully appreciated. Thanks Megalos (paul) In <div id="chart_rt">%3$s</div> below, it is populated with a string that always begins with a number followed by a colon (from 1: to 25:). I see that ltrim removes characters from the beginning of a string but I don't see how to compensate for the extra character in 10: through 25: function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<div id="charts">'; if ( $num_items !== -1 ) { $rss->items = array_slice( $rss->items, 0, $num_items ); } //start count $i = 1; foreach ( (array) $rss->items as $item ) { printf( '<div id="chart_lt">'.$i.'</div><div id="chart_rt">%3$s</div>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), htmlentities( $item['title'] ) ); //increment $i++; } echo '</div>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } } I have a variable called $content and I want it to stop execution at 25 characters... How can this be accomplished? Thanks in advance. Hi.. I am relatively new. I am trying to show an image link in my code below: $image = "<img src=<imgpg/" . $part_no . ".JPG />"; <td class = "guide_body" width = "66%"></td><td align = "center"><?php echo $image;?> There is more code but these are the problem lines I believe. Both are within the php environment.
This is producing:
It is supposed to look like this: So it is adding %3C for some reason between localhost and imgpg directory. I have no idea why this is happening. Is there something I can do to prevent this from happening? Or is there something I can do to erase the extra characters. (I'm not sure if they might be different though at some point. I have the same problem both on my local computer and the remote server.) Thanks very much for any help!! I have sen this function before but can not remember what it is or how to code it. It allows you remove only defined characters from the end of the string. I am not looking to replace any occurrence anywhere in the phrase, just the end. For example lets say I want to remove"ld!" from phrase "Hello World!" That function would return "Hello Wor" Thanks I have a form with some dropdownlist that get populated dynamically(depends on what the user chooses) with jquery and an xml file. In the form I have a button that takes the info and populates another form with the values of the ddl. I have coded script which populates the second form with jquery and the name of each input get dynamically added like so: Code: [Select] <input type="text" value="'+model+'" name="Model_'+model+'" id="'+model+'" readonly size="'+model.length+'" /> <input type="text" value="'+model+'" name="Model'+model+'" id="'+model+'" readonly size="'+model.length+'" />> <input type="text" value="'+color+'" name="Color'+color+'" id="'+color+'" readonly size="'+color.length+'" /> <input type="text" value="'+part+'" name="Part'+part+'" id="'+part+'" readonly size="'+part.length+'" /> <input type="text" value="$'+price+'" name="Price'+price+'" id="'+price+'" readonly size="'+price.length+'" /> <input type="text" value="'+qty+'" name="Quantity'+qty+'" id="'+qty+'" readonly size="'+qty.length+'" /> <input type="text" value="'+total+'" name="Total'+total+'" id="'+total+'" readonly size="'+total.length+'" /> What I want to do is grab the name of the element and remove the underscore and everything else form rileft to right so I am left with just the word before the underscore. I tried using substr($key,0,-28) but that wont work since everything after the underscore will have a different length. I was wondering if there is a way i can keep everything before the underscore and remove the underscore and everything after that. Thanks in advance for any input I get. This is probably a simple one. I just couldn't find a tutorial to the specific thing I'm trying. I have a string that looks like: "(abbreviated name with.) second abbrev. name." I'm trying to find a way to break this apart so I can have: $var1 = "abbreviated name with." $var2 = "second abbrev. name." I've looked at substr and a couple others and I'm not sure quite how to do this, because the ')' could be in a differing location. Hi Guys I'm returning to programming after 5 years, almost a newbie. I have a field(column) in a MySQL database table that has strings of characters separated by a delimiter (||). For example: (TOM||PAUL||HARRIS) I would like to separate the strings into an array. Something like this: ARRAY[0] = 'TOM'; ARRAY[1]='PAUL'; ARRAY[3]='HARRIS'; Can some one tell me how to do this? TIA. How could I split a string in half but not in the middle of a word? $information = "This is the string of text, however at some point in the sentence a word may get split in half."; $cut = round(strlen($information)/2); ///where to cut (50%) $split1 = substr($information, 0, $cut); //first half $split2 = substr($information, $cut); // second half I have a string of mixed Japanese or Chinese and Western characters and I would really like to leave the western characters and remove the others. Is there any way to detect which UTF-8 characters are Japanese/Chinese and to remove them? I have tried to use this which I found on another thread but my version of PHP (5.3) will not allow the /u in the following Code: [Select] echo "<BR>".preg_replace('/[^\u4E00-\u9FFF]+/', '', $string); I have tried using various combinations of /p (these, plus others) Code: [Select] echo "<BR>".preg_replace('/\p{Bopomofo}+/u', '', $string); echo "<BR>".preg_replace('/\p{Hiragana}+/u', '', $string); and the /x{} option tells me the numbers are to large Code: [Select] echo "<BR>".preg_replace('/[^\x{4E00}-\x{9FFF}]+/', '', $string); My string for this example is this but any combination of western and Japanese/Chinese characters are possible in the title. 2011.12.06 19:00-20:00 / ふくいちライブカメラ (Live Fukushima Nuclear Plant Cam) | Uploaded: 06 Dec 2011 Thanks for any help. Alright, so I have a textarea where users can put in text. Everytime they put [ani] and click submit, I want the output to change [ani] into an html code: <img src="mypic.gif"> Is this possible? |