PHP - Removing Characters From A String
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++; Similar TutorialsIn <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 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. Last question for the week now. Almost finished. All I need to do is: Remove characters from the beginning and the end of a string. Essentially: Code: [Select] a:4:{s:4:"full";s:111:"http://www.mothernatureinc.co.uk/wp-content/uploads/2011/02/166637_482678026567_509616567_6394964_6868412_n.jpg";i:96;s:117:"http://www.mothernatureinc.co.uk/wp-content/uploads/2011/02/166637_482678026567_509616567_6394964_6868412_n-96x96.jpg";i:60;s:117:"http://www.mothernatureinc.co.uk/wp-content/uploads/2011/02/166637_482678026567_509616567_6394964_6868412_n-60x60.jpg";i:32;s:117:"http://www.mothernatureinc.co.uk/wp-content/uploads/2011/02/166637_482678026567_509616567_6394964_6868412_n-32x32.jpg";} Needs to become Code: [Select] http://www.mothernatureinc.co.uk/wp-content/uploads/2011/02/166637_482678026567_509616567_6394964_6868412_n.jpg Any ideas? How can I remove certain string from a statement. For example: A blagh blah blah blah blah. http://blah.com Where I would want to remove everything from "http" and after. So the final statement would show as: A blagh blah blah blah blah. Hi, May I know how can I remove all characters after the first 3 characters after . e.g : 123.512645124 I want to maintain 123.512 without rounding up. Please advise and thanks. I wanted to use strstr and trim functions but I am not able to use it to get what I want.. can some guru please assist .. thanks again There are good ways to keep only English characters in a string. But what is the easiest way to keep all alphabetic characters (whether in English or other languages like Russian, Japanese, etc) by removing all sign characters like !@#$%^&*()":;' ? I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! Hi all, In my string I have hidden characters that has a shape of square. When I print the string, it shows questions mark. When I opened it with notepad, it show a square shaped character. I want to remove this character in my strings. I have searched the web. Somebody says its carriage return but i think it is not. Could you please help me with this issue. Thanks alot. Hi all, I have an array of data. I am looping through this data to generate a CSV file. However, if there are commas in any of the elements then this will throw out the structure of the CSV file. My question is, how do I loop through the array before I use it to strip out any commas and replace with a space? Thanks for your help. What I want to do is simple: The string "this_is_an_example.php" should return "this_is_an_" while: "this_is_an_example_filename.php should return "this_is_an_example_" Is there a simple function which can cut off the part after the last _ ? I have been looking and trying several functions, but can't seem to find the right one for this. (the last _ being cut off of course wouldn't be a problem I couldn't live with :-) ) Any help will be greatly appreciated! Hello guys, I want to remove part of a string and convert it to a var instead of echoing it out.. How would I do it.. $string = "temp_photo/testing.jpg"; I want to remove temp_photo so the out put should be $filename2 = testing.jpg Please advise.. Thanks, Dan hi im having trouble removing ' from strings
so say
$name = "D'vion";
$newname = str_replace("'","",$name);
but this just returns the same.
thanks matt
Hey all, I'm using the form 'method="get" action="results.php"' on my search form... Say someone uses my 'Photo search' to search my database for aircraft, and leaves all fields blank. In this case, the only field of the search is 'aircraft'. This will take the user to 'results.php?aircraft='. Is there anyway to remove the sting if there is no search value? So it would just read 'results.php'? This is the code i have so far: Code: [Select] <?php if(isset($_GET['aircraft'])){ $aircraft = $_GET['aircraft']; } if($aircraft==""){ $aircraft = mysql_query("IGNORE aircraft"); } ?> Thanks in advanced! Hey guys! I found a flush function and it seems to be working well, but sometimes it will cut off characters. It's very strange. Here's my flush function: function out($str) { echo $str."<br />\n"; vbflush(); } function vbflush() { if (ob_get_length()){ @ob_flush(); @flush(); @ob_end_flush(); } @ob_start(); }And I'm calling it like this:out('Waiting 30 seconds until execution');And this is my output: Code: [Select] Waiting 30 seconds until executioAnyone know why? %3$s displays a string of text that always begins with a number followed by a colon (from 1-25 only). 1: 2: 3: etc... Is there a way to remove the number and the colon entirely and leave the rest of the string intact? Code: [Select] function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { 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 title="%2$s"><strong>'.$i.'</strong></div><div>%3$s</div>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), htmlentities( $item['title'] ) ); //increment $i++; } Ashley Does 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, Any help would be great. I'm filtering and rss feed and to create a new feed with some <item>'s removed. Here is a snippet from the source file. <item> <title><h1>Indians, Pacers and Colts attendance is only part of story</h1></title> <link>http://www.newsweek.com/the-score/2010/07/29/indians-pacers-and-colts-draw-similar-sized-crowds/PARAMS/post/21385</link> <description></description> </item> <item> <title><h1>Declining attendance forcing Speedway to make changes</h1></title> <link>http://www.newsweek.com/declining-attendance-forcing-speedway-to-make-changes/PARAMS/article/21369</link> <description></description> </item> <item> <title><h1>Three issues that could derail Indy's 2012 Super Bowl</h1></title> <link>http://www.newsweek.com/the-score/2010/07/27/three-issues-that-could-derail-indys-2012-super-bowl/PARAMS/post/21341</link> <description></description> </item> I'm wanting to use the link tag to detect the item that need to be removed for the new rss feed. All <item>with <link> that contain http://www.newsweek.com/the-score/ as the beginning of the link need to be filtered out. Here is my code so far. <?php echo '<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:media = "http://search.yahoo.com/mrss"> <channel> <title>CLE Calendar</title> <description>CLE Calendar</description> <language>en-us</language> <pubDate>June 14, 2010</pubDate> <lastBuildDate>June 14, 2010</lastBuildDate> <ttl>15</ttl>'; ?> <?php $rss = new SimpleXMLElement('http://www.newsweek.com/mobile-app/rss/feed?rssId=18&premium=false', null, true); ?> <?php foreach ($rss->channel->item as $items): ?> <item> <title><?php echo '<h1>' . $items->title . '</h1>'; ?></title> <link><?php echo $items->link; ?></link> </item> <?php endforeach; ?> </channel> </rss> Thanks in advance, MK This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=321479.0 |