SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using bbcode in a html layout coming from database and converting the bbcode..

    Hi there,

    I have a html layout stored in mysql database and i want to use php code to read the html and replace the bb code with proper html/php functions

    here is the html code

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>NaTo- The North Atlantic Treaty Organization - </title>
    </head>
    <style type="text/css">
    	body
    	{
    	background-color:#890303;
    	}
    	
    	#container
    	{
    		width:936px;
    		height:800px;
    		float:left;
    	}
    	#headerleft
    	{
    		width:936px;
    		height:482px;
    		float:left;
    		background-image:url(images/header.gif);
    		background-repeat:repeat;
    	}
    	.L
    	{
    		margin-top:125px;
    		margin-left:10px;
    		color:#000000;
    	}
    	#Login
    	{
    		width:452px;
    		height:223px;
    		float:left;
    		background-image:url(images/newlayout_complete_02.gif);
    		background-repeat:no-repeat;
    	}
    	.d
    	{
    		margin-left:120px;
    		margin-top:50px;
    	}
    	.e
    	{
    		margin-left:120px;
    		margin-top:105px;
    	}
    	#newmem
    	{
    		width:484px;
    		height:223px;
    		float:left;
    		background-image:url(images/newlayout_complete_03.gif);
    		background-repeat:no-repeat;
    	}
    	#navname
    	{
    		width:245px;
    		height:41px;
    		float:left;
    	}
    	#nav
    	{
    		width:228px;
    		background-image:url(images/navbg_07.gif);
    		background-repeat:repeat;
    		float:left;
            height:741px;		
    	}
    	#navpanel
    	{
    		width:228px;
    		float:left;
    	}
    	.n
    	{
    		margin-top:10px;
    		margin-left:95px;
    	}
    	#content
    	{
    		
    		width:691px;
    		float:left;
    		background-image:url(images/cntbg_06.gif);
    		background-repeat:repeat;
    		min-height:782px;
    	}
    	#footer
    	{
    		width:936px;
    		height:45px;
    		float:left;
    	}
    	#navfooter
    	{
    		width:145px;
    		height:45px;
    		float:left;
    	}
    	#cnt
    	{
    		width:691px;
    		height:56px;
    		float:left;
    	}
    	#allance
    	{
    		margin-left:750px;
    		margin-top:110px;
    	}
    	#navf
    	{
    		float:left;
    	}
    </style>
    <body>
    	<div id="container">
    		<div id="headerleft">
    			<div id="allance">NO Clan Alliances</div>
    
    		</div>
    		<div id="Login">
    			<div class="d"><form method="post" action="index.php?cmd=login">
    				<table>
    					<tr>
    						<th>Username:</th>
    						<th><input type="text" name="username" value="" /></th>
    					</tr>
    
    					<tr>
    					<th>Password:</th>
    						<th><input type="password" name="password" value="" /></th>
    					</tr>
    					<tr>
    						<th><input type="submit" name="login" value="Login" /></th>
    					</tr>
    				</table>
    
    			</form>
    </div>
    		</div>
    		<div id="newmem">
    			<div class="e">[newmemb]</div>
    		</div>
    		<div id="navpanel">
    			<div id="navname"><img src="images/navtitle_05.gif" width="228" height="41" alt=""></div>
    			<div id="nav">
    				<div class="n"><table>
    	<tr>
    		<th><a href="index.php?cmd=Home">Home</a></th>
    	</tr>
    <tr>
    		<th><a href="members.php">Console</a></th>
    	</tr>
    
    	<tr>
    		<th><a href="index.php?cmd=Members">Members</a></th>
    	</tr>
    	<tr>
    		<th><a href="index.php?cmd=Ranks">Ranks</a></th>
    	</tr>
    	<tr>
    		<th><a href="index.php?cmd=diplomacy">Allances</a></th>
    	</tr>
    	<tr>
    		<th><a href="index.php?cmd=medals">Medals</a></th>
    	</tr>
    	<tr>
    		<th><a href="punbb/index.php">Forum</a></th>
    	</tr>	
    </table>
    [musicplayer]
    </div>
    			</div>
    		</div>
    		<div id="content">
    			<div class="n">
    The php code

    PHP Code:
    function musicplayer()
    {
        echo 
    "Music Player";    
    }
    function 
    newmem()
    {
        echo 
    "New Member";    
    }
    //
    function template()
    {
        include(
    "dbconnect.php");
        
    $kQuery="SELECT * FROM template Where selected='1'";
        
    $rs=mysqli_query($con,$kQuery);
        if(!
    $rs)
        {
            echo 
    "Error:".mysqli_error($con);
        }
        else
        {
            
    $count=mysqli_num_rows($rs);
            if(
    $count>0)
            {
                
    $data=mysqli_fetch_assoc($rs);
                
    extract($data);
                
    $Header=stripslashes($Header);
                
    //
                
    $n="[newmemb]";
                
    $genav=newmem();
                
    //$Header=str_replace($n,$genav,Header);
                
    $a="[musicplayer]";
                
    $ge=musicplayer();
                
    $aPlaceholders = array('[newmemb]','[musicplayer]');
                
    $aReplacements = array($genav,$ge);
                echo 
    str_replace($aPlaceholders$aReplacements$Header);
                
    //
            
    }
            else
            {
                echo 
    " Error:The Header you are Looking for cannot be found";
            }
        }
        

    So what is wrong with my php code??

    Can anyone help me with my php error? as its not being displayed correctly above.

    Thanks,William

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Both functions musicplayer() and newmem() do not return a result, but echo it directly. Therefor the variables $genav and $ge equal null.

    Best regards,
    Vince
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my php code for my music player function only problem is that its not being displayed the php side of things when i run the below

    PHP Code:
    include("dbconnect.php");
                                
    //
                                
    $cQuery="SELECT * FROM music";
                                
    $result=mysqli_Query($con,$cQuery);
                                if(!
    $result)
                                {
                                    return 
    "Error:".mysqli_error($con);
                                }
                                else
                                {
                                    
    $count=$result->num_rows;
                                    if(
    $count>0)
                                    {
                                        return 
    '<table>
                                        <tr>
                                            <th><form method="post" action="">
                                            <select name="music">
                                            <option value="">Select Song</option>'
    ;
                                        while(
    $data=mysqli_fetch_array($result))
                                        {
                                            echo 
    '<option value="'.$data['link'].'">'.$data['name'].'</option>';
                                        }
                                        return 
    ' </th>
                                        <tr>
                                        <tr>
                                            <th><input type="submit" name="playmusic" value="Play Music"></th>
                                        </tr>
                                        </table></form>'
    ;
                                    }
                                    else
                                    {
                                        return 
    "Music Play List Empty";
                                    }
                                }
                                if(isset(
    $_POST['playmusic']))
                                {
                                    
    $music=$_POST['music'];
                                    if(
    $music)
                                    {
                                        return 
    "<embed src=\"$music\" width=\"120\" height=\"15\" />";
                                    }
                                } 
    With the above code my php and html layout gets messed up

    Home
    Console
    Members
    Ranks
    Allances
    Medals
    Downloads
    Forum

    Your Profile
    Member Commander in Chief demo
    Email william@cerebralfix.com
    Recruited By: Intial Account
    Date Joined 2010-01-5
    Days in Clan: You have been in the clan for 0 years 3 months

    Members
    Logout
    Change Password
    Chatroom
    Change Information
    View Logs
    Private Messages
    Clan Enteraniment Center
    Add Downloads
    Set Games Played
    Set Recruitment Date
    Officers
    Add Member
    Post News
    Promote Member
    Generals
    Award Medals
    Add Allance
    Disable/Undisable
    Demote Member
    Remove Medal
    Obtain Password
    Rename Member
    Remove Medals
    Unban IP
    Manage Clan War
    Leaders
    Manage Clan Wars
    Create Clan War
    Create Squad
    Manage Squads
    Set Members Rank
    Members Ip
    Ip Ban
    Failed Logins
    Edit Header/Admin Info
    Update History
    Add Custom Page
    Add FAQ
    create squad
    Demote
    Webmaster
    Set webmaster
    Update Templates
    Manage Ranks
    Manage Forums
    Add Forum
    FAQ Management
    Database Backup
    Add Games Played
    Manage Games Played
    Restore Database Backup
    Add Console Option
    Manage Console Options
    Delete Clan War
    getpass
    news letter
    Set Rules
    console perms
    Set Webmaster
    Header/Settings
    Custom Pages
    Add FAQ
    Mass Set Rank


    No Clan News At the Moment

    So Why does it with my music player function?

    Thanks,William

  4. #4
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oke, first of all, go through the following documentation:


    My point being:
    PHP Code:
    function directOutputAndReturnValue ()
    {
        echo 
    'This string is not being returned, but is direct output.';
        return 
    'This value is returned, and can be stored in a variable';
        
    // After 'return;' or 'return $anyValue;' is ommited, the rest of the function will not be executed.
        
    echo 'This value will never be printed.';
        return 
    'This value will never be returned.';
    }

    $myVariable directOutputAndReturnValue();
    // $myVariable now contains the string 'This value is returned, and can be stored in a variable'
    // The string 'This string is not being returned, but is direct output.' is printed directly to the output. 
    FOR SALE: 1 set of morals, never used, will sell cheap

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so ur saying i'd i have to put the function to varable eg $var1=myfunction(); in the str replace just got [watever] to replace it with $var1 am i correct?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •