PHP - Please Help With Stripping Out Accented International Characters
Similar Tutorialsor need to extract all tags <p> from a site in Italian //////////////////////////////////////////////////////////////////////// header('Content-Type: text/html; charset=iso-8859-1'); function curl_file_get_contents($url) { $curl = curl_init(); $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; curl_setopt($curl,CURLOPT_URL,$url); //The URL to fetch. This can also be set when initializing a session with curl_init(). curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,10); //The number of seconds to wait while trying to connect. curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request. curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); //To fail silently if the HTTP code returned is greater than or equal to 400. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header. curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect. curl_setopt($curl, CURLOPT_TIMEOUT, 5); //The maximum number of seconds to allow cURL functions to execute. $contents = curl_exec($curl); curl_close($curl); return $contents; } $get = curl_file_get_contents($url); function getTextBetweenTags($tag, $html, $strict=0) { /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ if($strict==1) { $dom->loadXML($html); } else { $dom->loadHTML($html); } /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the tag by its tag name ***/ $content = $dom->getElementsByTagname($tag); /*** the array to return ***/ $out = array(); foreach ($content as $item) { /*** add node value to the out array ***/ $out[] = $item->nodeValue; } /*** return the results ***/ return $out; } <?php $content = getTextBetweenTags1('p', $html); foreach( $content as $item ) { echo $item.'.'; } ?> ///////////////////////////////////////////////////////////////////////////////// My problem is that it does not recognize accented characters./// //////////////////////////////////////////////////////////////////////////////// "con un certo miglioramento del testo e, cosa più importante, con le firme dei sottoscrittori. scusate la ripetizione. che però, dicevano gli antichi, iuvat. un caro saluto. " Or need your help regards,cristian I 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 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 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> ';} } } First forgive me, I do not know if this is the correct forum for this question. I did not write the code but I have a feeling if its possible to correct it, then its probably coding. My question is, is there anyway to post larger News articles to the homepage. I am trying to post an article that a friend sent from another site onto mine (giving the other site proper credit). But the article is apparently too big. I do not know how many characters the article is, or what the character limit is set by Nuke 8.0. Is there anything that I can do? Thanks..oh and congrats on apparently being the only active PHP forums :-S I have tried a few others and they haven't made posts since 2011. Anyways thanks in advance for any and all help. Hi guys! I am learning PHP now and I am enjoying it. Im not an I.T. graduate that is why Im having very difficult time to understand codes. My problem is how to get the last character of a URL that I get using another php code. I can already post the URL on my page but it displays all the URL of the certain page that I get. Example: the URL is "http://mysite.com/page_1/pp1/?lang=zh" I only want to get the "?lang=zh". I am working under 3 languages and I want to get only that last part of the URL for me to continue my work. I dont exactly know what string or filtering I will do to get that part only. Please help me guys. I will appreciate all your comments here. Hi What code would i use to take the first 2 letters of a post code so for example CM11 2AY I want the CM bit what command would strip the first 2 characters out? Thanks I want to be able to keep people from entering certain characters in a form. I've tried google, and had no luck so far. Thanks! $name = "D'Angelo" ok I'm running a mysql query as $query = " INSERT INTO TEST (ID, NAME) VALUES ('NULL','$NAME')"; If the name = "D'Angelo" the apostrophe would cause it to fail. Is there a way to do this without striping the characters? 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. Im not sure f this is the right spot for this or not but... I have a website that has a content box that has a fixed height and width. How would i make it so after the box is full it puts a link to read more at the bottom of it? Also images may be used as well. Its also for a wordpress blog |