Jump to content

explode and replace


hackalive

Recommended Posts

so I have a string which is ($layout) "<1><2><b><3></b>";

now I also have a DB with the following ($content) "<1>This should disply as 1<2>This should display as 2<3>This should be bold and display as three"

I have the mysql code to get the above DB data

but now I need to explode and replace so that "This should disply as 1" replaces <1>

 

I have this code but it dosent work :-(

 

		$exploded = explode("<", $content);
	for($i=0;$i<strlen($exploded);$i++) {
		$content = str_replace("<$i>", $exploded{$i}, $layout);
	}

 

any help much appreciated

Link to comment
https://forums.phpfreaks.com/topic/196762-explode-and-replace/
Share on other sites

This is what I have at this moment, and it is now replacing but only for the last value of $i, not the others in between (eg if <AL3> only shows <AL3> and not 1 and 2 which DO exists

function article_content($page_layout){
$mysqli = db();
$uri = uri();
$theme = theme_id();
$qry_article_content = "SELECT * FROM `articles` WHERE `uri`='$uri' ORDER BY `position`"; 
$result_article_content = $mysqli->query($qry_article_content, MYSQLI_STORE_RESULT);
while ($array_article_content = mysqli_fetch_array($result_article_content)){
	$article_content = $array_article_content['content'];
	$article_priority = $array_article_content['priority'];
	$article_layout = $array_article_content['layout'];
	$article_position = $array_article_content['position'];
	$article_layout = articles_layout($article_layout);

	$split = preg_split("/[<AL]*[>][\s]*/", $article_content);
	for($i=0;$i<sizeof($split);$i++) {
		$article_content = str_replace("<AL$i>", $split{$i}, $article_layout);
	}
}
return $article_content;
}

Link to comment
https://forums.phpfreaks.com/topic/196762-explode-and-replace/#findComment-1032955
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.