Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_replace #contentM:x#

Status
Not open for further replies.

elck

Programmer
Apr 19, 2004
176
NL
Hi There
I am looking to replace ... #contentX:x# ... with

... Somethingorother firstarg=$1 secondarg=$2 ...

where X and x are single characters, where, in the example, S1='X' and $2='x'

preg_replace is the best solution, but I cannot fin the right searchargument.

I know my explanation is not very clear, but does anyone understand?
 
would something like this work:

Code:
<?
$html ="#ContentSomething goes here:another argument goes here#";
$html .= " lots more filler text and then another ";
$html .="#ContentArgument43:argumentZZZ#";
$pattern = "/#Content(.*?):(.*?)#/";
preg_match_all($pattern, $html, $matches);
for ($i=1; $i<count($matches); $i++){
	//you might want to do this
	//$firstarg = urlencode($matches[$i][0];
	//$secondarg = urlencode($matches[$i][1]);
	echo "somethingorother?firstarg=".$matches[$i][0]."&secondarg=".$matches[$i][1]."<br/>";
}
?>
 
Mh, yeah this gets close. I think I can figure it out now, Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top