Jump to content


Photo

how do I do this?


  • Please log in to reply
2 replies to this topic

#1 curtm

curtm
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 15 March 2006 - 06:43 PM

How would I accomplish the following...

In a string containing either

action="target.php"

or

action=target.php



how would I strip out everything except target.php ? I am going to be using this on multiple forms, and i have no idea whether the forms will have the quotes or not.

thanks!

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 15 March 2006 - 06:58 PM

You're going to want to use preg_match() with regular expressions to grab that out. You basically want to look for "action=" and grab everything from there until you find a space, and then do a str_replace on the quotes.

Info: PHP Manual


#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 March 2006 - 07:04 PM

[!--quoteo(post=355434:date=Mar 15 2006, 01:43 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 15 2006, 01:43 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How would I accomplish the following...

In a string containing either

action="target.php"

or

action=target.php
how would I strip out everything except target.php ? I am going to be using this on multiple forms, and i have no idea whether the forms will have the quotes or not.

thanks!
[/quote]

you can grab all the actions out of a string using a combination of the following:
$string = "action=\"target.php\" | action='target.php' | action=target.php";

// first match for those with single or double quotes
preg_match_all("/action=(['\"])(.+?)(?:\\1)/i", $string, $matches);

// next, match for those with no quotes at all
preg_match_all("/action=([a-z.\/_]+)/i", $string, $matches2);
echo "<pre>\n";
print_r($matches);
print_r($matches2);
echo "</pre>\n";


hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users