PHP - Moved: Preg_replace And Unicode Letters
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=331361.0 Similar TutorialsHow in php using the preg_replace php function can i allow only the basic english a-z letters, numbers 0-9 and unicode code letters and remove anything else? I'm looking for a method to replace everything between brackets. The patterns that I'm looking for are defined: "/\[([2-9TJQKA][hdcs])\]/" The pattern inside the bracket could accur 2 or even 3 times inside the brackets. For example first occurance would be [Ac Kd], here I want to replace Ac into an imge and Kd too. Later in the text I will most of the time get 3 sets, instead of two: [Jc Td 9d]. The sets always consist of [2-9JQKA][hdcs] and also in this order. Another example: [2d 2s 2h], or [3s 4h 5c]. If I use the following function, it would not work optimally because some texts do contain some of those sets which should not be converted, ONLY the sets between the brackets: $haystack = setReplace($haystack); function setReplace($haystack) { $array = array("2s", "2h", "2d", "2c", "3s", "3h", "3d", "3c", "4s", "4h", "4d", "4c", "5s", "5h", "5d", "5c", "6s", "6h", "6d", "6c", "7s", "7h", "7d", "7c", "8s", "8h", "8d", "8c", "9s", "9h", "9d", "9c", "Ts", "Th", "Td", "Tc", "Js", "Jh", "Jd", "Jc", "Qs", "Qh", "Qd", "Qc", "Ks", "Kh", "Kd", "Kc", "As", "Ah", "Ad", "Ac"); for($i=0;$i < count($array);$i++) { $result = str_replace($array[$i], "<img src=\"/images/".$code[$i].".png\">",$haystack); } return $result; }Any ideas? Edited by dde, 20 January 2015 - 10:21 AM. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=333172.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=318062.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=332527.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=350441.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347057.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=346278.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320391.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=330098.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306005.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347016.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347065.0 Hi, I have been working with inserting unicode characters into mssql database from a php application. My php web application displays the chinese characters as i entered and retrieves from database properly. But when I take a look at the database the fields are populated with some other values other than the characters i inserted. When i developed the same application in ASP.net the database has correct values inserted into it. Here is my code in php: Code: [Select] <?php // direct insert $var = mssql_connect('RAL-DEV-SQL01','TestDBSa','TestDB$@'); $selected = mssql_select_db('TestDB', $var); $myVar="日常生活"; $myChineseVar=$myVar; echo $myChineseVar; $query = "insert into TestChinese (TestName) values (N'{$myChineseVar}')"; $result = mssql_query($query,$var); echo "Inserted<br>"; echo $query; echo "<br>Result<br>"; $result2 = mssql_query("SELECT TOP 10 * FROM [TestChinese] order by SeqNum desc",$var); while($nt=mssql_fetch_array($result2)){ echo "$nt[SeqNum] - "."$nt[TestName] -"; echo "<br>"; } mssql_close($var); ?> Can someone help me with this problem Thanks Hi there guys, can any1 help me out to sort this thing. I'm using a simple php email script to send emails from online form (registration). Since i'm using unicode (cyrilic) font, i'm recieving an unreadable email from my php script. Here's the script (mailer.php): Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset="UTF-8" /> <title>Mecavnik</title> </head> <body> <!-- Reminder: Add the link for the 'next page' (at the bottom) --> <!-- Reminder: Change 'YourEmail' to Your real email --> <?php $ip = $_POST['ip']; $hp1 = $_POST['hp1']; $hp2 = $_POST['hp2']; $hp3 = $_POST['hp3']; $hp4 = $_POST['hp4']; $hp5 = $_POST['hp5']; $IP = $_POST['IP']; $hp6 = $_POST['hp6']; $hp7 = $_POST['hp7']; $hp8 = $_POST['hp8']; $hp9 = $_POST['hp9']; $hp10 = $_POST['hp10']; $hp11 = $_POST['hp11']; if (eregi('http:', $notes)) { die ("Ne ne! ! "); } if(!$hp8 == "" && (!strstr($hp8,"@") || !strstr($hp8,"."))) { echo "<h2>Error</h2>\n"; $badinput = "<h2>Error</h2>\n"; echo $badinput; die ("Error."); } if(empty($hp1) || empty($hp2) || empty($hp3) || empty($hp4) || empty($hp5) || empty($hp6) || empty($hp7) || empty($hp8 )) { echo "<h2>123</h2>\n"; die ("Error."); } $datum = date("l, F j, Y, g:i a") ; $subject = "Custom subject"; $message = "Firma: $hp1 \n Ime: $hp2 \n Prezime: $hp3 \n Email: $hp8 \n Telefon: $hp4 \n Konfekcijski broj: $hp5 \n Spavanje: $hp6 \n Prevoz: $hp7 \n "; $from = "From: $hp8 \n"; mail("evlj@something.bla", $subject, $message, $from); ?> <?php header( 'Location: http://blabla/123/123.html' ) ; ?> </p> </body> </html> Email that i have previously recieved: Code: [Select] Firma: Тестирам Ime: Упишите Ваше име Prezime: Упишите Ваше презиме Thanks in advance I have an index.php code. The code doesn't recognize UTF-8. The php identify the right part (one txt has many infos) from a .txt file and send that information to browser. Can I send this information to a specific email address instead of browser? And if Yes, can I say to this code to calculate more than one day but for more? Is this possible? Please help me with that. Thanks! [attachment deleted by admin] Hi, I am writing a PHP program to send SMS using HTTP API gateway. I use cURL to launch the URL. I am getting problems when I send UNICODE chars in the message. I am getting simply square boxes instead of UNICODE chars. When I launch the same URL directly in a browser it works well. Following is the code snippet currently I have. $message = "unicode chars here"; $launch_api = "http://xxxsss.com/send.php?message=".$message."&sender=aaa&to=xxxx&type=2&username=bbbb&password=cccc"; $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_URL,$launch_api); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec ($ch); curl_close ($ch); Could some one please help me what I am missing? I am trying to retrieve an xml file from a webservice. I cant use the original server since it gags on non latin characters, unicode?, that is what the LOC says. The other server does work with non latin characters BUT it is too slow with file_get_contents, takes a minute to get anything, so slow you cant even use it in the program. YET, retrieves the xml fast in the browser window. So, what can I do that will work fast like it should? Code: [Select] //original database server, file_get_contents is faster, about 3 to 10 seconds //$request= 'http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve'.$query.$test2.'&startRecord='.$offset.'&maximumRecords=20'; //new one that can handle non latin characters //file_get_contents is SLOW, so slow to be unusable, about a minute or more $request='http://lx2.loc.gov:210/LCDB?version=1.1&operation=searchRetrieve'.$query.$test2.'&startRecord='.$offset.'&maximumRecords=20'; $raw_xml = file_get_contents($request); $filename = dirname(__FILE__)."/loc.xml"; $fp = fopen($filename, "w"); fwrite($fp, $raw_xml); fclose ($fp); Hi Guys
I have a regex conundrum that at first I thought would be very easy but then appears to be quite hard :/
I want to match a string with a regex where the regex can only pass if it contains letters and numbers (nothing else) and it has to contain at least one of each.
I've been trying out lookaheads but just can't get it right.
Any help is appreciated.
Drongo
|