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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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