Jump to content

BSlepkov

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BSlepkov's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The answer may be so simple that I've totally overlooked it, but I've been struggling to use preg_match with strrpos. Can it be done? If so, my coding would be a heck of a lot more efficient and elegant. Basically, what I want to do is extract the first specific tag (<tr ... > or <li ... >) to the left of a string. The problem is not my regular express (#<(tr|li)[^<]*?>#i), just getting something like ... strrpos($some-xhtml-text, preg_match('#<(tr|li)[^<]*?>#i', $some-xhtml-text, $tag)); ... to work. Any takers?
  2. Sorry wildteen, I assumed made it clear from my opening line to the post, that I already do block undesirables. I just didn't clarify how ... using mod_rewrites.The example url I gave is a mock legitimate link that for anyone other than spiders, I could just present as regular text.
  3. Assuming I've already blocked undesirable bots, I now want to identify 'friendly' crawler or spider type activity from a normal surfer so as to not offer links for resorting lists - i.e. http://mywebsite.com/dir1/content_list.php?sort=date&order=asc Such a script would set a flag variable when client 123.45.678.90 accesses X number of pages within X number of seconds. Could this be done without having to use sessions or cookies?
  4. Well, well, well. Rarebit, I'm pleased to say that your suggestion ultimately did pay off. There are instances, where, after running through my PhpCleanup function, $excerpt did indeed contain strings like in this example: ... I have <?php hotlink('letters of recommendation', true, "http://mywebsite/references.php"); footnote(); ?> from the ... In order to resolve such cases, then after this ... $excerpt=PhpCleanup($found[0]); then ... ob_start(); $excerpt = eval("?>".$excerpt); $excerpt = ob_get_contents(); ob_end_clean(); ... forced the <?php script to be assessed. So, an extra thank you goes out to rarebit!
  5. Just a minor correction to my last post. Since I didn't call PhpCleanup() with $excerpt=PhpCleanup(), the final lines in that function should be ... $excerpt=htmlspecialchars_decode($fixedstr) ... not $fixedstr= and the return statement is not needed. FTI - establishing $fixedstr in the first place isn't needed, except I did so to monitor my progress on replacing each variation of the variables.
  6. I just posted the results of my struggles with preg_ functions at http://www.phpfreaks.com/forums/index.php/topic,218141.0.html You should find that somewhat instructive. Also, with regards to any possible white spaces, your script should look more like this: preg_replace( '/<tr>\s?<td height="290" colspan="3">\s?</td>\s?</tr>\s?<tr>\s?<td height="163" valign="top" colspan="3">\s?</td>\s?</tr>/','',$sStripDOC ) I'm no expert, but I think that should help you somewhat. BTW, what's with the '%' at the start and end of your preg pattern?
  7. I don't know what to tell you, rarebit. Heaven knows I tried it your way without any success. That's not to say it wouldn't work provided all the correct combinations of php functions were applied in the proper sequence. However, your last post did help remind me that since I was working within a user function, I first needed to extract previously defined variables. The following is what ultimately worked for me. I hope others manage to stumble on this in their search for similar solutions. With the original $excerpt in hand, I called PhpCleanup() ... below function PhpCleanup() { global $excerpt; $fixedstr=$excerpt; # NOTE! For whatever the reason, the regex search pattern in preg functions must be enclosed thusly ... '//' or "//" $varextract=preg_match_all('/\$([a-zA-Z0-9]*)/', $excerpt, $vars); $varlisting=$vars[0]; foreach ($varlisting as $key=>$var) { if (!$$var) { $varname=$vars[1][$key]; $$var=$GLOBALS[$varname]; $fixedstr=preg_replace('/(<\?=)?\$' .$varname .'( ?\.|\?>)/', $$var, $fixedstr); } } $fixedstr=htmlspecialchars_decode($fixedstr); return $fixedstr; } // end PhpCleanup Other than the note I embedded in the function above, here's what I learned in my struggles: 1. Since I originally converted $fixedstr with $fixedstr=htmlentities($excerpt) in order to get the preg_replace to acknowledge the '<' and '>' characters, the preg_replace had to be constructed thusly ... preg_replace('/(<\?=)?\$' .$varname .'( ?\.|\?>)/', $$var, $fixedstr); 2. I needed $fixedstr=htmlspecialchars_decode($fixedstr) in order to get the final results displayed as true HTML
  8. Thanks, rarebit. Your answer still leaves me with much to struggle with, but it's a start. And yes, I too learned by just struggling with trial and error - an ongoing process that never really ends.
  9. Actually rarebit, the more I look at your solution and research into ob's usage, the more confused I become as to how and where to apply it in my case. I, and less experienced php'ers could use a more expounded answer. Otherwise, for me, I'll be spending the next few days playing around. Also, bear in mind that in my particular circumstances I think that the best approach is completely replace/remove passages such as <?=$WStart?>Urban%20Renewal<?=$WStop .$SStart?>Urban%20Renewal<?=$SStop .$GStart?>Urban%20Renewal<?=$GStop?> from $excerpt followed by $excerpt=strip_tags($excerpt) Otherwise, in order to maintain the integrity of any site related links appearing in the excerpted html I would have to do more programming than I care to at this point.
  10. Thanks for that. I'll play around with it and see what happens. Using ob's is going to be a new territory for me. So I've got a few questions... 1. Can I use ob_start at any point in a script, i.e. after headers have been called and contents partially displayed? 2. When you say, if I provided the variables filled in, to which (set of) variables are you referring? $rawtext, <?=WStart?>, $excerpt? 3. I'm looking at your solution, trying to think how and where I should apply it. Is $x or $s supposed to be any one a the variables I mentioned?
  11. First timer here. Greetings. Ok. First off, I've gotten damn good at this php stuff, however this one's got me stumped. Hope there's an answer out there. Here's what I'm trying to do: I've written a script that searches my website files (php, txt and doc) for given phrases. Once I've determined a relevance factor, I want to display (a portion of) a paragraph containing the found phrase. For now, let's focus on an example php file. I'm working with: $rawtext=file_get_contents($file, 'FILE_TEXT'); The following line gives me a paragraph. The (adjusted) results for each variation follow. BTW, the search phrase is smart growth: preg_match('/(^|\n)(.*?'.$found[0].'.*?)(\n|$)/i', $rawtext, $found); $excerpt=htmlentities($found[0]); Gives me: <p />My last ten years have been dedicated to <a href="<?=$DbaseSite?>information-and-stats.php" target="_blank">researching matters pertaining to local governance, urban renewal and 'sustainability'</a>. For the past four of those years <a href="<?=$RootDir?>about.php" target="_blank">I have involved myself in related policy-defining initiatives</a> at all levels of government. All of those initiatives relate to smart growth,<?=$WStart?>Smart%20Growth<?=$WStop .$GStart?>Smart%20Growth<?=$GStop .$SStart?>Smart%20Growth<?=$SStop?> urban renewal,<?=$WStart?>Urban%20Renewal<?=$WStop .$SStart?>Urban%20Renewal<?=$SStop .$GStart?>Urban%20Renewal<?=$GStop?> and for the most part, socio-economic sustainability. I am making my position known, as I have a vested interest in how my city and region address those matters that are defining 21<sup>st</sup> Century society. $excerpt=$found[0]; ... gives me: My last ten years have been dedicated to researching matters pertaining to local governance, urban renewal and 'sustainability'. For the past four of those years I have involved myself in related policy-defining initiatives at all levels of government. All of those initiatives relate to smart growth,Smart%20GrowthSmart%20GrowthSmart%20Growth urban renewal,Urban%20RenewalUrban%20RenewalUrban%20Renewal and for the most part, socio-economic sustainability. I am making my position known, as I have a vested interest in how my city and region address those matters that are defining 21st Century society. The problem of course, stems from snipets like '<?=$WStart?>' not being processed. Before attempting to just use strip_tags($excerpt), I've tried to get around this issue by first replacing strings like '<?=$WStart?>Urban%20Renewal<?=$WStop .$SStart?>Urban%20Renewal<?=$SStop .$GStart?>Urban%20Renewal<?=$GStop?>' with: $excerpt=preg_replace('\<\?=\?\>([a-z]+)(\+|%20|\-)?([a-z]+)?\<\?= ?\.\?\>([a-z]+)(\+|%20|\-)?([a-z]+)?\<\?= ?\.\?\>([a-z]+)(\+|%20|\-)?([a-z]+)?\<\?=\?\>', '', $excerpt); I'm sure there's a better regex formula, but that's not the point. I've testing this out ten ways to Sunday, and it appears that for some reason, '<' and/or '>' result in blanking out the entire variable. As a test, ... preg_replace('\?=\?', 'oops', $excerpt) ... worked, but even preg_replace('\>([a-z]+)(\+|%20|\-)?([a-z]+)?\<', '><', $excerpt) yields an empty $excerpt. So then...what's happening, or not? As best I can tell, there's no reason for the variables in the short tags not to be processed, but now that I think of it, I should try to replace <?=$variable?> with <?php echo $variable ?>. Seems I also managed, without luck, replacing <?php echo $variable ?> with {$variable}. Finally, I'm not seeing any errors being registered during any of these efforts. Thanks for your time. B.
×
×
  • 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.