Simple Smiles Not so simple

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Simple Smiles Not so simple

Post by danharibo »

My Code to Change : ) to :) isnt working to good :/

Code: Select all

<?
function addbbcode ($vartoproc);
{
  $Procstringsmile = str_replace(':)', '<img src="./image/smile.gif">', $vartoproc);
return $Procstringsile;
}
?>
Parse error: parse error, expecting `'{'' in c:\program files\easyphp1-8\www\sufsite\function\bb_code.php on line 2
What am i doing wrong this time :roll:
Edit I just noticed One problems thank to your php Tags ;)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

take the semi-colon off this line

Code: Select all

function addbbcode ($vartoproc);
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Code: Select all

<?php
function addbbcode ($vartoproc)
{
  $Procstringsmile = str_replace(':)', '<img src="./image/smile.gif">', $vartoproc);
return $Procstringsmile;
}
?>
Fixed short tags. Fixed semi colon on line 1. Fixed variable spelling.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Now its not Changing :) to <img....>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

How do you know?

Run this and tell us the output

Code: Select all

<?php
function addbbcode($vartoproc) {
  return str_replace(":)", '<img src="./image/smile.gif">', $vartoproc);
}

echo addbbcode('Hello ');

?>
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

that worked :)
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

But the Main String won't Print it :(
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

danharibo wrote:But the Main String won't Print it :(
Explain further.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

look:
http://danharibo.dyndns.org/sufsite
It prints : ) instead of ./image/smile.gif
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I thought it worked?

What are you doing differently there to the example I gave you?
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

ptinting it FROM another file?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Printing what from another file? I don't understand.

Show your full code.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Index,php:

Code: Select all

<Head>
<Title>******</Title>
</Head>
<body bgcolor="#00000" TEXT="#fffff">
<? include('Header.php'); // Include Head file
include('./function/bb_code.php');
?>
<table Align="Left" >
<tr ALIGN="center"><td>Navigation</td></tr>
<tr ALIGN="center"><td>[<a href="./index.php">Home</a>]</td></tr>
</table>
<Table align="center" >
<Tr>
<td>
<?
if(isset($_GET['page']))
{
$page = $_GET['page'];
$page2 = str_replace('..', '', $page);
$temp= $page2.'.txt';
$page2 = $temp;
$fp = fopen($page2, 'r'); // Open Page .txt for reading from beginning
$read = fread($fp, '1000'); // Read from the file pointer
$output = addbbcode($read);
echo $output; 
}
else{
$fp = fopen('index.txt', 'r'); // Open Page .txt for reading from beginning
$read = fread($fp, '1000'); // Read from the file pointer
print($read); 
}
?>
</td>
</Tr>
</Table>
<center>
<? include('./Footer.php'); //Include the footer, to sav e us having to Change all the files Individualy
?>
bb_code.php:

Code: Select all

<?
function addbbcode($vartoproc) {
  return str_replace("Smile", '<img src="./image/smile.gif">', $vartoproc);
} 
?>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I presume your addbbcode function actually has

Code: Select all

:)
in it rather than

Code: Select all

Smile
?
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Still won't work
Post Reply