PHP - Stripping Extension (and More) From Url
Hi all,
I just managed to make a little mod_rewrite rule which manages to interpret url's without the extension and calls the right file with the extension (ie. /articles calls articles.php) . But now i am left with another question which i am almost certain has nothing to do with mod_rewrite, but rather with a php trick. In case someone enters on my site www.mydomain.com/laalalalala.php How do i get rid of that last part(the extension for example)? Do i maybe have to get the GET['var'] and run it through a regex and reload the page with the stripped version? That was all i could think off but it sound so complicated. if anyone has an idea i would love to hear it cheers! P.s.s if anyone want's that rewrite rule, let me know. I saw quite some people on the internet looking for it Similar TutorialsI have a small script that prints the contents of a log on my server but it's removing tags from the output. An example would be: <username> data here is being printed as: data here removing: <username> I do not want it to strip these out of the output. How do I avoid this? Code: [Select] <? $cmd = "tail -5 /opt/mserver/server.log"; exec("$cmd 2>&1", $output); foreach($output as $outputline) { print ("$outputline\n"); } ?> It seems like there should be a dedicated php function to strip a SPECIFIC tag, rather than the functionality of strip_tags. I'm using this: Quote function stripSingleTags($tags, $string) { foreach( $tags as $tag ) { $string = preg_replace('#</?'.$tag.'[^>]*>#is', '', $string); } return $string; } But this will not help me if for example I want to trip out scripts <script> ... </script>. Is there a better way? Hi, this is probably really simple for the majority here, but it's catching me out. I want to know what I need to add to the code below to strip <> HTML tags from the field post_title. Hope somebody can help. Thanks in advance. Code: [Select] <?php mysql_connect("********", "********", "********") or die(mysql_error()); mysql_select_db("website_news") or die(mysql_error()); $data = mysql_query("SELECT * FROM news_posts ORDER BY post_date DESC LIMIT 0, 5") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Print "<font color='black' face='arial'><li><a href='/website/news/?p=".$info['ID'] . "'>"; if ( strlen($info['post_title']) > 60) { $PostTitle = substr($info['post_title'], 0, 60); print $PostTitle. "..."; } else { print $info['post_title']; } Print "</a> <font color=#666666><i> - posted on "; $date = date('j M \'y', strtotime($info['post_date'])); Print $date; Print "</i>"; } ?> i'm having problems with apostrophes causing an error on my contact form. I've tried stripslash and also str_replace but i can't get it to work. what am i doing wrong? thanks Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "test@test.com"; $email_subject = "test"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['contact_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $contact_name = str_replace("'", "&#039;", $contact_name); $contact_name = $_POST['contact_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$contact_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Contact Name: ".clean_string($contact_name)."\n"; $email_message .= "Agency/Company Name: ".clean_string($last_name)."\n"; $email_message .= "Email Address: ".clean_string($email_from)."\n"; $email_message .= "Dates Required: ".clean_string($telephone)."\n"; $email_message .= "Type Required: ".clean_string($check_msg)."\n"; $email_message .= "Any other info: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> thanks <?php } ?> Hi All, Hope you can help, I'm having problems with the strip_tags code, I'm having problems getting it to work with certain tags, the code below shows my issue: $print_description = <span style="color: #ff99cc; font-size: large">4 x BLUE handmade clay feet</span> $print_description = strip_tags($print_description); //remove html because of danger of broken tags I've cut down the code to show the problem. So I want to strip the Span tags; the problem I am having is as soon as you have a style attribute with more than one attribute and you use a ; symbol strip_tag will strip the entire content of the <span>AND ALL THE TEXT IN THE MIDDLE</span>. I want to just be left with '4 x BLUE handmade clay feet' If I take the ; out and just have one style it works fine. I am using tiny_MCE so don't have the option not to use what it makes me use. I've searched the net and have tried a few things to make it work but now I'm at a loss. Any help would be gratefully received. In querying my database, I'm Selecting nameFirst and nameLast, and it produces a name like Joe Smith. I'm trying to match a photo with the name. Right now I'm uploading photos into a folder naming the file (e.g. SmithJoe.jpg). For reasons that involve writers being able to upload and access photos, I'm trying to use an image plugin. When uploading photos, it strips capital letters, so SmithJoe,jpg goes in as smithjoe.jpg, and it's not matching my database query. Here is the code I'm working with that works quite well with this one exception: $query = 'SELECT * FROM wp_playerRank'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { if ($line['wpID'] == $wp_tagID) { echo '<div class="player">'; // Here is the code that produces the image. I need to get rid of capital letters for ease of use echo '<div><img src="/wp-content/uploads/' . $line['nameLast'] . $line['nameFirst'] . '.jpg"></div>'; echo '<div class="playerData">' . $line['height'] . ' '; if ($line['position'] == 'PG') {echo 'Point Guard';} elseif ($line['position'] == 'SG') {echo 'Shooting Guard';} elseif ($line['position'] == 'SF') {echo 'Small Forward';} elseif ($line['position'] == 'PF') {echo 'Power Forward';} elseif ($line['position'] == 'C') {echo 'Center';} echo '</div>'; echo '<div class="playerData">' . $line['hschool'] . '</div>'; echo '<div class="playerData">' . $line['summer'] . '</div>'; echo '<div class="playerData">Class of ' .$line['year'] . '</div>'; if ($line['committed'] == 'y') { echo '<div> <br>Committed to <strong>'. $line['college'] . '</strong></div> ';} } } Hi all. i have problems with making a questionnaire. i have done a single questions but i have no idea how to add them al ltogether so they work as switch function. i`ve attached one of the questions. could anyone suggest how i make answers into a list rather than just a line of options? Hi there, trying to use PCNTL. I've recompiled PHP with --enable-pcntl in configure as described in PHP manual, but when I call pcntl_fork() I receive back " Fatal error: Call to undefined function pcntl_fork() ". What am I missing??? Thanks in advance Muflo Just started working with PHP and wrote a PHP extension in C. Got it working with hard coded variables and started to work on feeding it 3 string arguments as input. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &acct, &acct_len,&userid, &userid_len, &passwd, &passwd_len) == FAILURE) { RETURN_NULL(); } When I execute the extension with 3 arguments I always get the following. Code: [Select] [XXX@XXXVIPH01 smxauth]$ php -r "smxauth('myacct','nobody','password');" PHP Warning: smxauth() expects exactly 1 parameter, 3 given in Command line code on line 1 I thought the "sss" would dictate the number of args expected but it doesn't seem to work that way (for me at least). Using php-5.1.6 Any thoughts? Thanks Tim PHP v. 5.3.8 What is libxml extension and how would I know if it's enabled? My book told me Note To take advantage of SimpleXML, make sure PHP's libxml extension is enabled. I have a variable that holds the name of a File... Code: [Select] $origFileName = $_FILES['userPhoto']['name']; What is the best way to just get the File Name from this? Debbie Hey guys! I just joined this forum today, and I'm wondering about something... I see a lot of sites, and in the code of the site, style sheets and javascript includes are references in a manner similar to this... "href='http://www.somesite.com/css/css.php/someDirectory/style.css'" How is this done? The path following the "css.php" is what confuses me. Thanks for any information you have! How do I know if Filter extension is on with my webhost? Or does it always work with PHP5? If I cannot use it, can someone recommend a good regex to validate EMAIL addresses?? Thanks, Debbie Hi everyone, Sorry not sure if this is a php or html problem. Im using php and a html form to upload images to my site, i have made it so that jpg, jpeg, gif and png images can be uploaded. The problem im having is displaying the image. Code: [Select] <img src="images/<?php echo $name ?>.jpg" /> That works fine if a jpg was uploaded, but what if a png or a gif was uploaded? The $name is going to be unique, there will not be more than one image with the same name, so what do i have to do to display the image regardless of what the extension is? Thanks Hi, how do I extract just file extension? eg: $file="hello.xml"; $fileExt=??? print $fileExt; Any help much appreciated! so im trying this
$file is not a .txt file
if ($file != "." && $file != ".." && !is_dir("uploads/$fuser/$file") && (pathinfo("uploads/$fuser/$file", PATHINFO_FILENAME)!= "txt")
i tried this but doesnt work
Hello, I'm currently using this to block certain emails: $blacklisted = Array("email@email.com", "email2@email.com", "email3@email.com"); in with: if( !in_array( strtolower($email), $blacklisted ) ) { Ok, What I want to do, is be able to specify a domain extension such as '*@email.com' So anything with 'something'@email.com is blocked. I still wish to keep manual email address's in place aswell. Many thanks James I have an array that has data in it and its being sorted like this: Code: [Select] Source 1 (zip): filename.zip Source 1 (jpg): filename.jpg Source 1 (png): filename.png Source 2 (zip): filename.zip Source 2 (jpg): filename.jpg Source 2 (png): filename.png Source 3 (zip): filename.zip Source 3 (jpg): filename.jpg Source 3 (png): filename.png Id like the data to be sorted like this instead, but i dont know how to get it to sort this way: Code: [Select] Source 1 (zip): filename.zip Source 2 (zip): filename.zip Source 3 (zip): filename.zip Source 1 (jpg): filename.jpg Source 2 (jpg): filename.jpg Source 3 (jpg): filename.jpg Source 1 (png): filename.png Source 2 (png): filename.png Source 3 (png): filename.png Here's my code: any help is appreciated. thanks. for ($i = 1; $i <= 5; $i++) { $src[$i] = 'Source '.$i.' ('.$ext.'): '.$filename.''; array_multisort($src, SORT_ASC, SORT_STRING); } |