Jump to content

steven fullman

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

About steven fullman

  • Birthday 08/24/1972

Profile Information

  • Gender
    Male
  • Location
    London, England

steven fullman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, cags I've sent you a PM, I hope that's OK. Kind regards, Steve
  2. Hi cags, The 1 would be unique, and I'm intrigued why you don't think it would achieve the result! Kind regards, Steve
  3. Hi cags, I understand...but if I can ask one more question... ...(well, maybe two)... OK, so the URL *has* to be unique, but is it possible for mod_rewrite to "capture" the referrer url, and change it slightly... e.g. the referring url is http://mydomain.com/some-post/ and using mod_rewrite, change it to http://mydomain.com/some-post/1 ...where the 1 "masks" the /goto/somewhere/ instead ? Many thanks, Steve
  4. Thanks, Cags. I was hoping I could use mod_rewrite to display the REFERER URI (i.e. the same URL which had the link in the first place) instead of the /goto/somewhere URL. In pseudo-code: For any URL matching the pattern /goto/*, display the REFERER URI in the address bar instead. Is that not possible? Thanks again cags. I really appreciate your time. Best wishes, Steve
  5. Hi cags, Thank you so much for your reply...and I'm not surprised you don't understand me ...I'm notoriously BAD at explaining things! AND I'm a mod_rewrite newbie... Having said that, let me try to explain a little better! OK, My visitor clicks on an internal link, e.g. : http://www.mydomain.com/goto/phpfreaks ...which will redirect them to phpfreaks.com (we need to assume the link address is obfuscated, so they can't see it in their browser status bar if they hovered over it) I NEED them to visit http://www.mydomain.com/goto/phpfreaks in order to drop a cookie. So, they click on http://www.mydomain.com/goto/phpfreaks ...I drop a cookie, and then I immediately redirect them to phpfreaks.com BUT, my question is: I don't want my visitor to **see** the "intermediate" http://www.mydomain.com/goto/phpfreaks address...I want them to click the link...and as far as they're concerned, they've gone straight to phpfreaks.com ...using mod_rewrite? I'm super-grateful for your help, cags, and I suspect I STILL haven't made myself clear... Just in case, here's another representation: When the visitor clicks that link, I don't want them to see the redirect URL in the address bar... Here's what I want them to see: http://mydomain.com/demo/my-test-post => internal link (/goto/phpfreaks) => they click link => http://phpfreaks.com ...what I don't want them to see (in red): http://mydomain.com/demo/my-test-post => internal link (/goto/phpfreaks) => click link => http://mydomain.com/goto/phpfreaks => http://phpfreaks.com Blimey! Does that make sense? Kind regards, Steve
  6. Hello, I sincerely help you can help with this scenario... I'm not sure this is possible, but here goes: I have a Wordpress blog, installed in a subdirectory of my website, e.g. http://www.mydomain.com/demo/ I have some permalinks, which all follow the same structure, like this: http://www.mydomain.com/demo/goto/google http://www.mydomain.com/demo/goto/yahoo http://www.mydomain.com/demo/goto/bing etc...i.e they all have /goto/*somewhere* (and the *somewhere* is a redirect to an external site). Wordpress handles the permalinks itself, as you can see in the .htaccess file Wordpress automatically generates: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /demo/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /demo/index.php [L] </IfModule> # END WordPress Here's what I'd REALLY like to happen (if possible)... I link to one of my custom permalinks in a blog post on mydomain.com, e.g. mydomain.com/goto/phpfreaks When a visitor clicks that link, the URL in the address bar should display as the page they are currently on So, here's what it looks like: My blog has a post called: http://mydomain.com/demo/my-test-post On that page, there's a link to: http://mydomain.com/goto/phpfreaks (which redirects to phpfreaks.com) When the visitor clicks that link, I don't want them to see the redirect URL in the address bar, so they see: http://mydomain.com/demo/my-test-post => click link => http://phpfreaks.com ...instead of: http://mydomain.com/demo/my-test-post => click link => http://mydomain.com/goto/phpfreaks => http://phpfreaks.com This sounds like something that should be possible using mod_rewrite...doesn't it? i.e. display REQUEST_URI for any link like /goto/* Does that make sense...and is it possible? Your help would be greatly appreciated, as I have been really struggling trying to get to grips with mod_rewrite & .htaccess! Many thanks, Steve
  7. @OP, you can find an alternative pattern that uses a look-behind instead of a look-ahead in this post: http://www.phpfreaks.com/forums/index.php/topic,258333.msg1215689.html#msg1215689 Thanks! I'll look into that...it looks exactly what I need! Kind regards, Steve
  8. There's a reason why I run these regex's at "page request"... I don't want to change someone's post's permanently. Kind regards, Steve
  9. This reply blew my mind. I had to send you a PM! Kind regards, Steve
  10. Hi there, Yes, I realise I need to give you a better understanding. OK, this code is for a Wordpress plugin. It performs several actions, but one of which replaces dictionary words with synonyms... Because Wordpress can display many articles on a single page, the code will cycle through all of them when a page is requested. Here's another example: function synonymize($string){ $buffer=$string; $folder= PLUGINDIR."/myplugin"; $synonymsfile = $folder.'/synonyms.txt'; if ( $synonymsfile = fopen($synonymsfile, "r")) { while (!feof($synonymsfile)) { $synonyms = fgets($synonymsfile); $synonyms = str_replace("\n", "", $synonyms); $synonyms = str_replace("\r", "", $synonyms); if(!strlen($synonyms) < 2) { $synonymlist = explode(",", $synonyms); $oldword = $synonymlist[0]; $synonym = $synonymlist[1]; $buffer = preg_replace("#(?=[^>]*(?:<|$))\b$oldword\b#s", $synonym, $buffer); $buffer = preg_replace("#(?=[^>]*(?:<|$))\b" . ucfirst($oldword) . "\b#s", ucfirst($synonym), $buffer); } } fclose($synonymsfile); } return $buffer; } So, as you can see, I open a text file (synonyms.txt)...the format is like this: abandonment,leaving behind abase,lower abash,humiliate abashed,embarrassed abate,stop abating,narrowing ABC,essentials abdicate,renounce abdication,resignation abdomen,belly abduct,kidnap abduction,kidnap ... ... 17,000 more lines ... ... zilch,zero zing,dynamism zip,vitality zipper,closure zippy,rapid zit,blackhead zombie,android So, here's what happens: 1. I open the synonyms.txt file read only. 2. I get a line, and remove any line ending characters 3. If the line is 2 characters or longer, I explode the line by the comma 4. I then perform the preg_replace to replace the word with it's synonym 5. I then perform the preg_replace again to replace an ucfirst version of the word with it's synoym 6. Get the next line, and perform steps 3-5 again Now, steps 3-5 end up being executed 17,000 times, each with 2 preg_replace calls. So, the problem I face is that, without the regex you kindly gave me in your first reply, I find that words within <html tags> also get "synonymed"...and with the extra regex code it runs particularly slowly. But the real issue is that I suspect the way I'm attacking the problem is all wrong. It seems like there must be a better way to achieve the same result without having to create 17,000 arrays and calling preg_replace 34,000 times...! I hope that makes sense, and I really appreciate your help. Kind regards, Steve
  11. Hi Salathe, Thanks for the reply! Well, I guess intensive is the wrong word. What I meant was the amount of function calls are (probably too) excessive. To perform this function across an article of, say, 500 words takes about 15 seconds. The problem is, there are probably 10 articles per web page that this function runs against... So, most of the time, my page times out before the function completes. If I take out the regex which filters out the <html> tags, it runs much faster. But, I wonder if there's a better way to perform the preg_replace without having to loop it 68,000 times? Kind regards, Steve
  12. Hi Cags! That's awesome, seems to work perfectly...thank you! I wonder if I can ask for a final piece of advice? If you look at my function from the first post, you'll notice it: 1. Opens up a text file of dictionary words (currently 17,000+) 2. Builds an array 3. Runs another function against the dictionary words (let's say for argument's sake, transforms them into unicode characters) 4. Then the function runs the regex you gave me. It does this 4 times, to account for different cases. Trouble is, the function performs the regex 17,000+ times x 4 (once for each dictionary word, and 3x for each case match)... As you can imagine, that's hugely intensive, and runs very slowly... Can you think of a more efficient way to perform the regex...without having to loop through so many times? Kind regards, and thanks again for your help. Steve
  13. Hello! I really hope you can help... I'm have a function which replaces keywords with...other keywords. The trouble is, it also replaces words within <html> tags...which is a problem, since I'm now replacing (for example) <div class="good"> with <div class="great"> ...which obviously breaks the rendering... What I'm trying to (and, Boy! have I been trying..) is to ignore anything inside <tags> I know preg_replace is the way to go, but I've been trying and failing for 2 days now... And I'd really appreciate your help. In short, I need my preg_replace to replace all instances of my keyword....unless it's in <html tags> I need someone smarter than me! Here's my code (without my attempt to "ignore" stuff within <html tags>): if (!function_exists("wordmash")) { function wordmash($parts) { $wordlist = file_get_contents('dictionary.txt', true); $dictionary = explode(",", $wordlist); $htmldictionary = array(); foreach($dictionary as $dicword) { $htmldictionary[] = htmlcode($dicword); $htmldictionary_u[] = htmlcode(strtoupper($dicword)); $htmldictionary_u1[] = htmlcode(ucfirst($dicword)); $htmldictionary_ucwords[] = htmlcode(ucwords($dicword)); } for($i=0;$i<count($dictionary);$i++){ $parts = preg_replace("/\b$dictionary[$i]\b/", $htmldictionary[$i], $parts); $parts = preg_replace("/\b" . strtoupper($dictionary[$i]) . "\b/", $htmldictionary_u[$i], $parts); $parts = preg_replace("/\b" . ucfirst($dictionary[$i]) . "\b/", $htmldictionary_u1[$i], $parts); $parts = preg_replace("/\b" . ucwords($dictionary[$i]) . "\b/", $htmldictionary_ucwords[$i], $parts); } return $parts; } } If you need more info...please let me know! Kind regards, Steve (I don't know the rules of this forum, but I'd like to buy the 1st person to clear this up for me a beer via PayPal...if that's acceptable?)
  14. Thanks dreamwest, One of the reasons I'm using preg is that I can specify word borders...str_replace seems too limited in that way (i.e. I want to match the EXACT string only, not the string within other words). I've tried using spaces to distinguish the exact pattern, but I fall over at the beginning and end of sentences...and using commas, etc... Is there a way around these limitations?
  15. Hi, I have a script with some options. I use regex to replace patterns in strings, but I seem to be using them incorrectly, because they very quickly break my max_memory_limit (by several orders of magnitude) This is strange, because I'm dealing with maybe 10 simultaneous strings of 500 words max. I'm clearly causing some kind of overly recursive syntax, but I can't see how... Any help you could give me to programme this better (or tell me where I'm going wrong) would be most appreciated $string = "this would be about 500 words long"; $parts = $string; // $parts would normally be a substring of $string; wp_wordmash($parts); wp_synonymize($string); wp_keyword2url($string); //html stuff follows here... function wp_wordmash($parts) { $wordlist = file_get_contents('dictionary.txt', true); $dictionary = explode(",", $wordlist); $htmldictionary = array(); foreach($dictionary as $dicword) { $htmldictionary[] = wp_htmlcode($dicword); $htmldictionary_u[] = wp_htmlcode(strtoupper($dicword)); $htmldictionary_u1[] = wp_htmlcode(ucfirst($dicword)); $htmldictionary_ucwords[] = wp_htmlcode(ucwords($dicword)); } for($i=0;$i<count($dictionary);$i++){ $parts = preg_replace("/\b$dictionary[$i]\b/", $htmldictionary[$i], $parts); $parts = preg_replace("/\b" . strtoupper($dictionary[$i]) . "\b/", $htmldictionary_u[$i], $parts); $parts = preg_replace("/\b" . ucfirst($dictionary[$i]) . "\b/", $htmldictionary_u1[$i], $parts); $parts = preg_replace("/\b" . ucwords($dictionary[$i]) . "\b/", $htmldictionary_ucwords[$i], $parts); } return $parts; } function wp_htmlcode($string) { $buffer= NULL; for($i=0;$i<strlen($string);$i++) { $buffer .= "&#" . ord($string{$i}) . ";"; } return $buffer; } function wp_synonymize($string){ $buffer=$string; $synonymfile = file_get_contents('synonyms.txt', true); $synonyms = explode("\n", $synonymfile); for($i=0;$i<count($synonyms);$i++){ $synonymlist = explode(",", $synonyms[$i]); $oldword = $synonymlist[0]; $synonym = $synonymlist[1]; $synonym = str_replace("\r", '', $synonym); $buffer = preg_replace("/\b$oldword\b/", $synonym, $buffer); $buffer = preg_replace("/\b" . strtoupper($oldword) . "\b/", strtoupper($synonym), $buffer); $buffer = preg_replace("/\b" . ucfirst($oldword) . "\b/", ucfirst($synonym), $buffer); $buffer = preg_replace("/\b" . ucwords($oldword) . "\b/", ucwords($synonym), $buffer); } return $buffer; } function wp_keyword2url($string){ $buffer=$string; $keyword2urlfile = file_get_contents('keyword2url.txt', true); $keywords = explode("\n", $keyword2urlfile); for($i=0;$i<count($keywords);$i++){ $keywordlist = explode(",", $keywords[$i]); $keyword = $keywordlist[0]; $url = $keywordlist[1]; $url = str_replace("\r", '', $url); $buffer = preg_replace("/\b$keyword\b/", '<a href = "' . $url . '">' . $keyword . '</a>', $buffer); $buffer = preg_replace("/\b" . strtoupper($keyword) . "\b/", '<a href = "' . $url . '">' . strtoupper($keyword) . '</a>', $buffer); $buffer = preg_replace("/\b" . ucfirst($keyword) . "\b/", '<a href = "' . $url . '">' . ucfirst($keyword) . '</a>', $buffer); $buffer = preg_replace("/\b" . ucwords($keyword) . "\b/", '<a href = "' . $url . '">' . ucwords($keyword) . '</a>', $buffer); } return $buffer; } As I say, the string passed to these functions is typically < 500 words. I've also included the comparison files (dictionary.txt, synonyms.txt and keyword2URL.txt)...HERE I hope you can help...I'm 99% certain I'm using preg_replace() wrong...because if I substitute it with str_replace() then my memory issues disappear. Problem is, I like preg_replace because it gives me the word border functionality. I'm just obviously doing it wrong! Any thoughts? Kind regards, Steve P.S. Please feel free to mock & laugh at me...as long as you can show me a better way! And if you need any more info, please ask
×
×
  • 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.