eg...
i want it to replace
Code: Select all
:Url:news.php:news:Code: Select all
<a href = news.php >news</a>Moderator: General Moderators
Code: Select all
:Url:news.php:news:Code: Select all
<a href = news.php >news</a>Code: Select all
<?
$NetCode = array("[Link:","#", "]");
$Actual = array("< a href = ",">","</a>");
$string = "a link will be like this [Link: index.php # Home ] ";
$new = str_replace( $NetCode, $Actual, $string);
echo $new;
?>any ideas why this will not worka link will be like this [Link: index.php # Home ]
Sami wrote:For syntax highlighting use [php_man]highlight_string[/php_man]()
For your BBcode/Smilies needs:Reference material: [php_man]foreach[/php_man](), [php_man]str_replace[/php_man]()Code: Select all
<?php $replaceArray = Array( // example links "Google"=>'<a href="http://google.com" target="_blank">Google</a>', "MSN"=>'<a href="http://msn.com" target="_blank">msn</a>'); foreach ($replaceArray as $old => $new) { $thestring = str_replace($old, $new, $thestring); } ?>
This works with me but you are missing the quotes around the URL and have some spaces too many for html. This works fine:almostsane wrote:Code: Select all
<? $NetCode = array("[Link:","#", "]"); $Actual = array("< a href = ",">","</a>"); $string = "a link will be like this [Link: index.php # Home ] "; $new = str_replace( $NetCode, $Actual, $string); echo $new; ?>
Code: Select all
<?
$NetCode = array("[Link:","#", "]");
$Actual = array("<a href="","">","</a>");
$string = "a link will be like this [Link: index.php # Home ]";
$new = str_replace( $NetCode, $Actual, $string);
echo $new;
?>