Jump to content

yaba

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by yaba

  1. May I rephrase my request: How can I get all instances of "blah" that do NOT belong in a URL, i.e. something starting with either http:// or www. Thanks again :)
  2. I was hoping something a lot simpler and less CPU consuming would exist. For the [img] tag, something like: [code=php:0] $blah= ".+?blah.+?"; $text = preg_replace( "#[^(\[img\])]".$blah."[^(\[/img\])]#i", "replaced", $text); [/code] Any feedback on something like this?
  3. I only need to check for two tags: url and img, so some part of the regex could be "\[(img|url)(=.+?)?\]" (I think) I'm not sure what exactly you meant there? Could you post an example? Thanks for replying :D
  4. Hi everyone, could you please tell me how can I get all instances of "blah" that are NOT included in things like [code] [img]...[/img] and [url=http://blah.com]..[/url] [/code] So, the following should not match: [code] [img]asdfa asdf asd blah asdg [/img] [url=aasdf blah]asdfgsdfg[/url] [url=asdf]asdf blah asdf[/url] [/code] while this should match once: [code] [img]asdfa blah asdf[/img] asdfas sdf blah asgf [url=blah]blah[/url] [/code] Thanks! :D
  5. Yup, that did it! Thanks ;) I indeed got confused trying to express myself!  ???
  6. I think your XMLHTTPRequest object send UTF-8 to your php script. In your php script then, you can convert it to your original encoding like this: [code=php:0]iconv("UTF-8","YOUR_ENCODING",$_GET['var'])[/code] and do whatever you want to do with it. When you need to return info from your php script, use XML if you need to return non-ASCII chars, like this: [code] header('Content-Type: application/xml'); $out = '<?xml version="1.0" encoding="ORIGINAL_ENCODING?>' . "\r\n"; $out .= '<report xml:lang="LANG_HERE"><message>'.$message.'</message></report>'; echo $out; [/code]
  7. Make a function like this (it takes as params the article string and its id to build the link): [code=php:0] function fixLength($str, $id){     $maxChars = 50;     if (strlen($str)>$maxChars){         $str= substr($str, 0, $maxChars )."...<br/><a href=\"index.php?article={$id}\">Read more &raquo;</a>";     }     return $str; } [/code]
  8. [code=php:0] <?php echo <<<OUT //put here all that stuff OUT; ?> [/code] make sure there's no white space after <<<OUT and no white space before and after OUT; ;)
  9. I'm not sure you can do this once you call the split() function. What I would do is put the field I want to sort by as the first thing for every line in my file and then sort the $readfile array using one of the... array sort functions (sort, ksort, asort etc), before splitting...
  10. I dodn't quite get the "This product textfield will then change depending on which product page the user is directed to the enquiry form from." bit, but here's a quick example to accomplish the first part: Product view page: [code] <form name="myform" method="post" action="enquiry.php"> <input type="hidden" name="prod_name" value="{$pname}"/> <input type="hidden" name="prod_id" value="{$pid}"/> <input id="btn" type="submit" value="Enquiry"/> </form> [/code] Enquiry page: [code] <form name="myform2" method="post" action="send.php"> <input type="text" value="{$_POST['prod_id']}: {$_POST['prod_name']}"/> </form> [/code] Of course, you need to adjust the variable names. And I would further process the form based on the product id, not its name. The name is only good for the customer's understanding. ;)
  11. A very quick and dirty way of doing this: [code=php:0] $rows = $db->query("my query here"); while ($r = $rows->fetch_assoc()){ $names[] = $r['name']; $ages[] = $r['age']; $sexes[] = $r['sex']; $addresses[] = $r['address']; } $out = "<tr><td>name</td>"; foreach ($names as $n) $out = "<td>".$n[$i]."</td>"; $out .= "</tr>"; $out .= "<tr><td>age</td>"; foreach ($ages as $a) $out = "<td>".$a[$i]."</td>"; $out .= "</tr>"; $out .= "<tr><td>sex</td>"; foreach ($sexes as $s) $out = "<td>".$s[$i]."</td>"; $out .= "</tr>"; $out .= "<tr><td>address</td>"; foreach ($addresses as $a) $out = "<td>".$a[$i]."</td>"; $out .= "</tr>"; echo "<table>{$out}</table>"; [/code] I bet this can be written in a better way, as this is not very efficient. And I haven't run this, maybe there are typos. And the first 2-3 lines assume you are using OO mysqli, you can easily change the way you fetch your rows. Hope this helps ;)
  12. Hello, I need a REGEXP that would match a phrase that contains a word starting with some characters, but would not match a phrase that starts with a word, starting with those chars! ??? Here's an example: search chars = 'abc' 'sss abcsss' (match) 'sss abc abcsss' (match) 'abc sss abcsss' (no match) I thought this (when calling from PHP) would work: [code=php:0]"SELECT * FROM words where wrd REGEXP '^[^({$chars})].*[[:<:]]{$chars}' ORDER BY wrd ASC";[/code] but it doesn't. It will match 'sss abc', but it won't match things like 'sss[b]abc[/b]sfg abc'. Any help greatly appreciated :D
  13. Right, roger that :) Could you elaborate a bit on the pattern you used please? I don't think I've encountered before \p, for example. And those '?<=' and '?=.' bits you used... And correct if I'm worng, the \1 is what is captured by the first set of parentheses, right? I.e. (?<=\p{Z}) I don't quite get it, too advanced for me. Any place I could check these out with examples etc? Couldn't find anything... Or some feedback? Thanks! ;)
  14. So are you saying I should "rebuild" every word I get off the DB to UTF8? That seems a lot of processing :/ Even if I did that, how do I replace say 'α' with $alpha dynamically?
  15. OK here's what I need to do: given $_GET['searchLetter'], I perform a FT search in my DB for all words/phrases that contain at least a word that starts with that letter. For example if $_GET['searchLetter'] = 'a', then search would return 'A dog', 'some phrase with ALetter', and so on... I then want to apply some css to highlight that letter (well, actually it can be a word or part of a word). With normal preg, I'd do it this way: [code=php:0]$word = preg_replace("/(.*)\b(".($_GET['searchLetter']).")(.*)/i", "$1<span class=\"highlightmatch\">$2</span>$3", $word);[/code] which works fine for english chars (and greek chars, on my local PC). Thanks once again for all the help :)
  16. Hello again! How would I translate something like this: [code=php:0]preg_replace("/(.*)\b(".($a).")(.*)/ui", "$1___$2____$3", ($b));[/code] to use \x etc? I mean, when the pattern contains some chars that are obtained dynamically, what do I do? To make it even more difficutl (!), what do I need to put to match both greek and latin (english) characters? So it would match for $a and $b being either both greek, or both english? :-\
  17. This certainly looks promising! I'll have a good look and report back... Thanks for all your effor effigy :)
  18. Yup, I normally put the "," in, just forgot to add it this time... UTF-8 didn't work :/ My host won't support basic stuff, showing them my code is extreme! preg also supports the /u option, but so far it didn't do anything. I didn't do anything with greek blocks though. How do I do that? What exactly do you mean? Thanks ;)
  19. If I just setlocale(LC_ALL "something") and then echo with NULL parameter, I still get "C". Don't know if that has anything to do anymore. I also discovered the iconv* functions, played with them, tried every possible combo, still nothing :/ Here's what I get atm: [code=php:0] $word="ααα ββ"; echo mb_detect_encoding($word)." 1) $word<br/>"; $word = preg_replace("/(.*)\b(.)(.*)/u", "$1__$2__$3", $word); echo mb_detect_encoding($word)." 2) $word<br/>"; $word="aaa bb"; echo mb_detect_encoding($word)." 1) $word<br/>"; $word = preg_replace("/(.*)\b(.)(.*)/", "$1__$2__$3", $word); echo mb_detect_encoding($word)." 2) $word<br/>"; [/code] (The wierd chars above are supposed to read $word = "ααα ββ"; ) [code=output] UTF-8 1) ααα ββ UTF-8 2) ααα ββ ASCII 1) aaa bb ASCII 2) aaa __b__b [/code] Don't know what to think anymore. A few days more and a mental institution will be the only way for me :/
  20. Yes, I did contact them and they installed a bunch of others too. Now, after the preg* is executed, the encoding doesn't change, and the string is there intact. But the preg* itself doesn't work, since it returns the whole string intact... :/
  21. Yes well, any UTF8 would probably be a good start, even the "installed" en_US.utf8. The problem is no matter what and how I call setlocale, when I print the locale set it always returns "C" (the posix thing)....
  22. the locale command doesn't exist on my host's shell. However, the common dir for locales contains the following: [code] ls /usr/share/locale/ C  POSIX  en_US  en_US.utf8 [/code] Some of those are empty dirs, but the en_US.utf8 which is probably the best shot here, is not. However, when I use setlocale(LC_ALL, "en_US.utf8"); I still get "C".... I can't believe my host only got ASCII!!! thanks once again :D
  23. First of all, thanks for keep trying to help. I appreciate it :) You are right.... This works fine on the server too: [code=php:0]$word = preg_replace("/(.*)(".($_GET['term']).")(.*)/i", "=>$2", ($word));[/code] No matter what I use to setlocale ("el", "el_GR", "UTF-8" etc), it always returns "C" on the server. In any case, I would think UTF-8 should work for greek characters. So does that mean even UTF-8 is not supported on my server? I noticed that according phpinfo() the 'default_charset' is currently set to 'no value'. Could that be it? Should I change it to 'utf-8' or something similar? Thanks again!
  24. This: [code=php:0] setlocale(LC_ALL, "en_US"); echo setlocale(LC_ALL,"")."<br/>"; [/code] produces this on my machine: [code] Greek_Greece.1253 [/code] and this on the host: [code] C [/code] Dunno if this helps or means anything, specially since this: [code=php:0] //$_GET['term'] is the first letter of the $word. echo $word."<br/>"; $word = eregi_replace("(.*)(".($_GET['term']).")(.*)", "=>\\2", ($word)); echo $word."<br/>"; [/code] produces this, on BOTH machines: [code] αλάργο =>α [/code] which is exactly what 's expected... So ereg works, preg doesn't... too bad since ereg don;t have things like \b and \W... :/
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.