PDA

View Full Version : str_replace


anthony
12-16-2009, 01:49 PM
Hi I got a cycling site where we are using www.openrunner.com to insert the cycling course , you can insert the course using google map.

This is an example of a course that they insert that shows up on the site.

<iframe width="700" height="400" frameborder="0" src="http://www.openrunner.com/displayRoute.php?id=404674&amp;w=650&amp;h=300&amp;k=1&amp;m=0"></iframe>

what I would like to do to have everyone inserting the same size is
to have the width="700" height="400" always at 700 and 400
and this part
displayRoute.php?id=404674&amp;w=650&amp;h=300&amp;k=1&amp;m=0
always at w=650 and h=300

I was wondering is there a way to do this with str_replace if someone inserted other values
thanks
tony

Tom E.
12-17-2009, 05:46 AM
Hi Anthony,

The short answer is ... you can use preg_replace to do what you need with something like this for each value you want to fix:$fragment = '<iframe width="123" height="456" frameborder...';
$fragment = preg_replace('/width="\d+"/', 'width="700"', $fragment);
$fragment = preg_replace('/height="\d+"/', 'height="400"', $fragment);
// etc.

anthony
12-17-2009, 05:50 AM
thanks tom will try
tony

Tom E.
12-17-2009, 05:57 AM
The long answer, as usual, starts with questions...

How does the iframe get into the page? Can the user paste arbitrary code? (huge security hole, unless access is restricted to trusted people)

Is the iframe HTML by itself, like in the code example above, or do you have to find it somewhere in the entire page?

Are multiple routes allowed on a single page?

Is the island Hurley's dream?

--

It seems like the only important bit of information is the route id. Is it possible to have a form where the user just submits the id from openrunner.com, then your code creates the iframe tag?

Then if you change your site design so that 800 pixel-wide maps would look better, you just have to update the section of code that generates the iframes.

-- Tom

anthony
12-17-2009, 07:43 AM
hi tom

the people who put in the code are in an ssl area they are teams who organize rides, on the ride oranizer can log in there. I like the idea about creating my own code with the id that could be the easiest thing to do
thanks again
tony