PHP - Moved: Validate Characters In A String
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=320682.0 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. 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);} ?> Am looking forward to removing all the numeric characters upto and including the leading "/" in 90/_featuredarticles/2011/12 Regards 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. 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++; 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. 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) 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 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? 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 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 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. 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 topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=358157.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=332254.0 |