Advertisement

11.11.2004 at 04:23AM PST, ID: 21203002
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Modifying content of web page on the fly

Asked by markauk in PHP Scripting Language

Tags: , , , ,

Scenario:
Users enter content which goes on a web site using Movable Type. Users are non-technical, but I need to enable a couple of things without requiring users to enter html, code etc. Specifically:
(1) catch any email addresses entered and print them in a format not readable by spambots
(2) allow easy insertion of images within the text

Planned solution:
Movable Type will output a static file for each entry based on a predefined template. This template will contain PHP code to provide the functionality I require. Use ob_start to route all output to a function which
(1) routes any email addresses found to a function (already written and working, uses javascript to 'mangle' addresses in a non machine readable format)
(2) looks for any instances of {image=file.jpg} and replaces with the relevant IMG html

The code I have so far is as follows:-
<?
//load email() function
require("dev/inc/email.inc");

function image($command) {
      //convert {image=[image filename] align=[left|right|center] caption=[caption in quotes]} to correct html
      preg_match("/image=([^\s}]*)/i",$command,$image);
      preg_match("/align=([^\s}]*)/i",$command,$align);
      preg_match('/caption.*"([^"]*)"/i',$command,$caption);
      $caption=stripslashes($caption[1]);
      //output correct html for IMG (or dummy text for testing)
      echo("IMAGE=$image[1] ALIGN=$align[1] CAPTION=$caption");
}

function callback($buffer) {
      //regexp for replacing emails with email() function
      $search[0]="/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+/ie";
      $replace[0]="email('\\0','\\0');";

      //regexp for replacing {image} with IMG html code by calling image() function
      $search[1]="/{image[^}]*}/ie";
      $replace[1]="image('\\0');";

      $buffer = preg_replace($search,$replace,$buffer);

      return($buffer);
}
?>

<html>
<body>
<p><b>Callback function called directly</b></p>
<?echo(callback('<p>An image might go here {image=img.jpg caption="hello there" align=right}</p><p>Just email me at email@somewhere.com</p>'));?>

<p><b>Callback function called through ob_start</b></p>
<?ob_start("callback");?>
<p>Just email me at email@somewhere.com</p>
<p>An image might go here {image=img.jpg align=right caption=hello there}</p>
<? ob_end_flush();?>
</body>
</html>

Problems:
(1) when calling the callback function directly (ie not through ob_start), the results of the replacements are output first, then the rest of the text.
(2) when calling through ob_start, no replacement results are output, just the buffer less the bits that matched.

Requirement:
Either help me to get this code working correctly, or suggest a better way to achieve the same. Note that over time I will probably add more replacements, so it needs to be flexible enough to accept an arbitrary number of replacements.

Thanks

mark.Start Free Trial
 
Loading Advertisement...
 
[+][-]11.11.2004 at 07:07AM PST, ID: 12555271

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.11.2004 at 07:11AM PST, ID: 12555329

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.11.2004 at 08:41AM PST, ID: 12556345

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.11.2004 at 03:34PM PST, ID: 12561033

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.11.2004 at 05:04PM PST, ID: 12561615

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.11.2004 at 10:38PM PST, ID: 12562992

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: php, fly, page, web, html
Sign Up Now!
Solution Provided By: Fenric
Participating Experts: 3
Solution Grade: A
 
 
[+][-]11.12.2004 at 05:16AM PST, ID: 12565143

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32