PHP - Convert The First Letter Of Every Paragraph To Upper Case
From what I understand we can use ucfirst to convert the first letter within a string to upper case. What I would like to know is if there is a function that exists that would convert the first letter of every paragraph to upper case.
For example: From: Code: [Select] This is a paragraph. is this the car blue? let's go for a pint of beer! To: Code: [Select] This is a paragraph. Is this the car blue? Let's go for a pint of beer! Does any such function exist? Similar TutorialsHi, I wonder if some one could help me. I am trying to set up a few rules to make sure that users create safe passwords on my site: I have the below check which makes sure that the user enters a word of at least 8 charachters long: Code: [Select] if( strlen($password) < $MaxPwdLength ){ $errmsg_arr[] = 'Password must be at least 8 charachters long '; $errflag = true; } Does anyone know how I could write an if function to make sure that the ser is entereing a password with at least one capital and one lower case letter in. Hope you can help. Thanks Ed I mostly if not always name my classes with the first letter capitalized.
I typically use enable autoloading as follows. I don't know when I started converting the class name to under-case. As such, however, I need to make the filenames undercase.
Is this the correct approach?
spl_autoload_register(function ($class) { $class=strtolower($class); if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php')) { require_once __DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php'; } }); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327423.0 hello, im trying to see if there is a function that can get the value of the last row in mysql and see what is in field initial (this is letters A-Z) and make it one letter higher. then, when it reaches letter Z, wrap around to A again. Morning all, I'm trying to query a user table and am receiving errors. In the mysql statement I am trying to SELECT all data from the table that matches the username of the person logged in. The error I am receiving is this: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\123\myaccount.php The database query is written correctly, if I am logged in as the user Admin then I recieve this message as well: Unknown column 'Admin' in 'where clause' from the or die(mysql_error());. In the database the username is: admin but I can login using Admin, is this an issue of upper and lowercase? The PHP code is below: Code: [Select] <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = $_SESSION[gatekeeper]"); while ($row = mysql_fetch_array($query) or die(mysql_error())); { echo"<div class='BlockContent'>"; echo" <table id='UserList'>"; echo" <tr>"; echo" <th>My Account</th>"; echo" </tr>"; echo" <tr>"; echo" <td id='left'>"; echo" </td>"; echo" </tr>"; echo" </table>"; echo"</div>"; } ?> hello, i have the following, which is sorting by id number with a horizontal line between. im trying to make it so that it is sorted by supplier with lines between each letter. Code: [Select] <?php if ($PreviousID!=0 && $ManID != $PreviousID) {?> <hr /> <?PHP } $PreviousID = $ManID; include 'config.php'; include 'javascript.php'; @mysql_select_db ("citycore", $conn) OR DIE (mysql_error()); $sql = "SELECT * FROM supplier ORDER BY supplier"; $result = @mysql_query($sql, $conn) or die(mysql_error()); //$row2 = mysql_query($sql, $conn); $PreviousID=0; while ($row = mysql_fetch_array($result)) { $ManID = $row['id']; $id=$row['id']; $supplier=$row['supplier']; $address=$row['address']; $city=$row['city']; $province=$row['province']; $postal=$row['postal']; $phone2=$row['phone2']; $phone=$row['phone']; $fax=$row['fax']; $email=$row['email']; ?> <div align="center"> <table border="1" width="95%" style="border-collapse: collapse"> <tr> <td><?php echo $row['supplier'];?></td> <td><a href="http://mapof.it/<?php echo($address .' ' .$city .',' .' ' .$province .' ' .$postal); ?>" target="_blank"><?php echo($address .' ' .$city .',' .' ' .$province .' ' .$postal); ?></a></td> </tr> </table> </div> <?PHP } ?> what php function would I need to use to let's say I have a string I went to the Store And I want to pass that string, or any string through some type of function that would output: I Went To The Store How in the world could I do this? am I overthinking this or is this extremely difficult? i want it so that the 1st letter in this text box when it Submited gets saved to the db as 1st letter <input name="title" type="text" id="title" size="50" /> Hiya! I have a file (see attached) that contains basic HTML for a page with multiple paragraphs. How do I check the length of each paragraph to find out if it is 30 characters or over? If the first paragraph is not equal to 30 characters, then it should move on to the next one, and so on. If a paragraph is found to be the correct length, I then need to extract the text from the <p> tags. If a none of the paragraph match 30 characters in length, then the code will need to choose the best length paragraph. Any help is greatly appreciated. Many Thanks, FishSword Hi, I have pagination system with FIRST LETTER separated and everything is OK.
$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]); if ($page <= 0) $page = 1; $per_page = 5; $startpoint = ($page * $per_page) - $per_page; $statement = "restaurants ORDER BY `name`"; // make foo the current db '" . addslashes($_GET['id']) . "' $result = mysqli_query($mysqli,"SELECT name FROM restaurants WHERE cuisine_ID_obsolete=5 ORDER BY name LIMIT {$startpoint} , {$per_page}"); if (mysqli_num_rows($result) == 0) { echo "No records are found."; } else { $lastFoundLetter = ''; // displaying records. while ($row = mysqli_fetch_array($result)) { $firstLetter = substr($row['name'], 0, 1); if ($firstLetter != $lastFoundLetter) { if ($lastFoundLetter != '') { echo "</br>"; } echo strtoupper($firstLetter) . "<br/>"; $lastFoundLetter = $firstLetter; } echo $row['name'] . "<br/>"; } } echo pagination($statement,$per_page,$page); ?>Function for pagination: <?php function pagination($query,$per_page=10,$page=1,$url='?'){ global $mysqli; $query = "SELECT COUNT(*) as `num` FROM restaurants WHERE cuisine_id_OBSOLETE = '12'"; $row = mysqli_fetch_array(mysqli_query($mysqli,$query)); $total = $row['num']; $adjacents = "1"; $prevlabel = "<img src='files/prev.png'>"; $nextlabel = "<img src='files/next.png'>"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; // //last page minus 1 $pagination = ""; if($lastpage > 1){ $pagination .= "<ul class='pagination'>"; if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>{$prevlabel}</a></li>"; if ($lastpage < 7 + ($adjacents * 2)){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } elseif($lastpage > 1 + ($adjacents * 2)){ if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>...</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>...</li>"; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>..</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } else { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>..</li>"; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } } if ($page < $counter - 1) $pagination.= "<li><a href='{$url}page={$next}'>{$nextlabel}</a></li>"; $pagination.= "</ul>"; } return $pagination; } ?>Problem is, since I have FIRST LETTER separated, with $per_page. How to exclude FIRST LETTER and "<br/>" from $per_page variable? Hello, I am attempting to develop a simple php script which will generate a 4 letter sequence when a button is pressed. However the sequence has a few rules it has to follow. For example: the letters have to be A B C D E F G H J K L M P Q and R The second letter must be a letter AFTER the first The fourth letter must be a letter AFTER the third There can't be 2 of the same number. I am a bit confused on how I will do this as I am quite new to php, I though about generating the first as $1, then generating the second as $2, then if $1 > $2, then I would regenerate $2 until it wasn't. Then repeating that for $4. However I am not sure on the coding which would be involved in doing this. If someone could give me a few pointers or a link to a website which would help me it would be much appreciated. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350684.0 I am trying to get a paragraph from a website. Everything works but the first letter is kept on missing. The code shown below is used to get the paragraph. Not sure why the first letter is missing. Please help!!! Code: [Select] if ( isset( $offer[ 0 ] ) ) { // Tidy it up - remove commas and weird Word chars $off = strip_tags( $offer[ 0 ] ); $off = substr( $off, strpos( $off, ";" ) + 1 ); $off = str_replace("'", "", $off ); $off = trim( $off ); } else { $off = "0"; } I want to be able to replace, let's say, every fifth letter from a string. The string is unknown, though, it could come from database, or a POST form. So I'm unsure if I could use str_replace. I think I may need to use preg_replace(), but I'm not not sure. Hi.. I have code for auto increment of JO Number, now it display: 120504001 by using this code: <?php $sql = "SELECT jo_number FROM job_order ORDER BY jo_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['jo_number'],0,3)); $currentSRYear = (int)(substr($row['jo_number'],2,2)); $currentSRMonth = (int)(substr($row['jo_number'],0,2)); $currentSRNum = (int)(substr($row['jo_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%03d", $currentSRNum); ?> now I want it to be: JO120504001 JO120504002 JO120504003 JO120504004 JO120505001 JO120504002 JO120504003 Any help is highly appreciated. Thank you so much hi, I have a list of towns and need to get the first letter from each town and just display it once before the start of that lettered group ie; what I have: Aberdeen Arundel Aberyswith Bath Bristol Brighton Cardiff coventry what I would like: A Aberdeen Arundel Aberyswith B Bath Bristol Brighton C Cardiff coventry here is the code which writes out my list: Code: [Select] <ul class="edgetoedge"> <?php while($row1 = mysql_fetch_array($locals)) { echo '<li class="forward"><a href="townpubs.php?RSTOWN='.$row1['RSTOWN'].'" rel="external">'.$row1['RSTOWN'].'<small class="listcounter">'.$row1['PubCount'].'</small></a></li>'; } ?> </ul> Hello $row[longdescription] contains a description of a product (complete with HTML mark-up). I would like to display the first 250 characters in the results of a search. I would also like to remove any images that may crop up. This is what I have so far... Code: [Select] echo strip_tags(html_entity_decode(substr(preg_replace('/<img[^>]*>/Ui', '', $row[longdescription]), 0, 250))); The thing is (as you guys can probably already see), it also counts the HTML mark-up as characters and I get very different outputs (especially if an image occurs). I'd appreciate if you could advise me as to the correct way of doing this. Thank you I am trying to create a glossary, and I am not sure how to group the letters of the same words underneath each other. Right now, it is appearing as this: A apple A animal A amazing A attention A aero A axiom B butt B butter b brilliant but i need it to appear as this: A apple amazing attention aero axiom B butt butter brilliant here is my code: $query = exec_mysql_query("SELECT *,substring(en,1,1) as term FROM translations WHERE substring(en,1,1) RLIKE '[$letter]' ORDER by en asc"); while ($row = mysql_fetch_assoc($query)) { $term = $row['term']; $enterm = htmlentities($row['en']); $esterm = htmlspecialchars($row['es']); $alt = htmlentities($row['alt']); $notes = htmlentities($row['notes']); if ($term == substr($enterm,0,1)) { echo "<b>$term</b><br />"; echo "$enterm - $esterm - $alt - $notes<br />"; } } } any ideas how i can fix this? Hi everyone, I have a script below, which uplads an image, however, the image name always starts with a capital letter, I want all letters to be small, how to adjust this please, thank you
$target_dir = ""; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = "$get_current_user.jpg"; $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo ""; /// was File is an image $uploadOk = 1; } else { echo "File is not an image<br>"; $uploadOk = 0; } } // Check file size if ($_FILES["fileToUpload"]["size"] > 10000000) { echo "Sorry, this image is too large, please resize using Paint<br>"; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Only JPG, JPEG, PNG & GIF files are allowed<br>"; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "There was an error<br>"; } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "Uploaded successfully (You may need to clear Cache to see the new image)"; mysql_query("UPDATE user SET user_image = 'https://.../images/users/$get_current_user.jpg' WHERE user_name = '$get_current_user' "); } else { echo ""; /// was Select a suitable image, file not uploaded yet } }
I'm trying to get a listing of my directory that shows the first letter and then all the names that start with that letter. Here is my code: Code: [Select] for($i = 65; $i < 91; $i++) { foreach (glob("{".chr($i).",".chr($i+32)."}*", GLOB_BRACE|GLOB_ONLYDIR) as $directoryname) { echo chr($i)."| ".$directoryname; } } But here's my output: Quote P | Project Red P | Projects P | Pants R | Resumes W | Warehouse Files W | warrior I want it to be like: Quote P | Project Red Projects Pants R | Resumes W | Warehouse Files Warrior I know I have to move the chr($i) since it loops, but I'm not sure where to go from there. |