PHP - Last Word Of A String Uppercase
Similar TutorialsI 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 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. Whats the quickest way to find a word in a string and wrap <b> tags around it? Code: [Select] $search = "php web"; $striing = "PHP is the web scripting language of choice"; Basically im looking for the output to be : "<b>PHP</b> is the <b>web</b> scripting language of choice" Folks, I want to find a Word in a string. If the word is found, i want to retrun TRUE else FALSE. $string: Sol 3 Drawer Chests Antique Pine Bedside Chest $word to be found: Chest Now the tricky part is: In the $string the $word occurs twice once its CHESTS (i mean the first occurance) then CHEST. If its found, i want to return TRUE else FALSE. I tried using strpos() but it just checks for CHEST and not CHESTS. How can it be achieved? Cheers Natasha I have been becoming more and more familiar with PHP over the past few months, but this problem stumps me. How can I take a string of words separated by spaces taken from an XML feed (example: word1 word2 word3 word4) and turn it into something like this: <a href="word1">word1</a> <a href="word2">word2</a> ... and so on. This has to be done on the fly, since it is taking the words from the XML feed, they change depending on the page. I want them to be in a vertical column, and be able to link each one to the search page for that word, so each link has to be different. An even more in-depth problem, how can I sort it then so that there are multiple columns if necessary, say one page only has 3 words, but another has 50. How can I split them up into multiple vertical columns, say with 10 words in each? Have I confused anyone yet? 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 Hi, and thanks for any help with this.
I have this but of php i have been trying relentlessly to get working.. for over a month. <?php $abs="one two three four words"; $mT = "testing for matching words"; $words=explode(' ', $abs); //$sf=($words); if (preg_match($words, $mT)) { echo "the url $mT contains a Word"; } else { echo "the url $mT does Not contain a Word"; echo "$words[4]"; } ?>
You see, I get a responce only using the last line "$words[4]", (obviously, because I am pointing it the Matching word, (ie: with [4]) Edited June 9, 2020 by x1705 better description. Problem - application produces MD5 PWs which are uppercase, code checks lowercase. Question- How to use uppercase check? Code: [Select] function checkPwd($x,$y) { //Checks if strings are empty if(empty($x) || empty($y) ) { //Strings were empty return false; } else if(strlen($x) < 4 || strlen($y) < 4) { //String length too short return false; } else if(strcmp($x,$y) != 0) { //Strings do not match return false; } else { //Password Determined valid return true; } } Question 2: Do I have to change it anywhere else, like PW generation? Code: [Select] function GenPwd($length = 7) { $password = ""; $possible = "0123456789bcdfghjkmnpqrstvwxyz"; //no vowels $i = 0; while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } function GenKey($length = 7) { $password = ""; $possible = "0123456789abcdefghijkmnopqrstuvwxyz"; $i = 0; while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } Thank you for reading Hi Friends, I am Anes I want to ensure all surnames are uppercase in php I use $surname = ucfirst(strtolower($dataField)); How do I ensure that any names such as O'Brien, don't result in O'brien thanks Our professor in PHP Programming is very choosy that he requires us to verify if the user enter the UPPERCASE format of the user name registered the program will show an invalid user. What he's trying to say is the user must enter a 100% identical to the username he registered. If the username registered is LOWERCASE he must enter a LOWERCASE username if the username registered is UPPERCASE he must enter an UPPERCASE username to LOGIN. Hello: I have this little bit of code to pull all the towns and zip codes from a mySQL database: Code: [Select] <?php $result = mysql_query("SELECT zip_id,city,abbr_state,full_state,zip FROM zip_codes WHERE abbr_state = '" . mysql_real_escape_string ( $_GET['abbr_state'] ) . "' ORDER BY `city` ASC"); while($row = mysql_fetch_array($result)) { echo "<a href=\"Stores.php?zip_id=".$row['zip_id']."\" title=\"My Products ". $row['city']. ", ". $row['abbr_state']." ". $row['zip']." | My Items ". $row['city']. ", ". $row['abbr_state']." ". $row['zip']."\">". $row['city']. ", ". $row['abbr_state']." ". $row['zip']."</a>"; echo "<div style=\"clear: both; margin-bottom: 15px;\"></div>"; } ?> Works fine (unless some can offer a way to "improve" the code). However, all of the City Names ($row['city']) were put into the database as ALL CAPITALS, which is a bit harder on the eyes to read. Is there a "PHP way" - working with the code I posted - that will transform the ALL CAPITALS to a more readable Capitalize (in other words, Capitalize just the first letter of each town). I know that CSS offers "text-transform" and if that is a solution I'm fine with that. I just need it to display that way, not re-write it in the database. Ideas? Solution? Thanks! Hi I have this script that saves data to a file, I was wondering how I can make the script write the title of the files in uppercase letters? I am new to coding mind I think is the relevent code: Code: [Select] foreach(array('daily','weekly','monthly') as $value) { $fp = fopen(DIR.$value.'_'.strtolower(str_replace('/', '', $data[$ccyValue][0])).'.csv', 'w'); if($fp) { $raw_data = array(${$value.'Pivot'}, ${$value.'_s1'}, ${$value.'_s2'}, ${$value.'_s3'}, ${$value.'_r1'}, ${$value.'_r2'}, ${$value.'_r3'}); $write_data = "Pivot, S1, S2, S3, R1, R2, R3\n"; $write_data .= implode(',', $raw_data); fwrite($fp,$write_data); fclose($fp); } else { die('Please make sure result folder is present or writable!'); } } } Thanks Antony Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks 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!
In PHP Version 8.0 shows error as : In previous versions of PHP it does not show any error. Please resolve the issue. |