Jump to content

PHPiSean

Members
  • Posts

    79
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

PHPiSean's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you very much Sandeep. Is there a way I could use this for italics URL and bold tags now? Eg: #i# #b# and #url#? Thank you very much for your help by the way
  2. Thanks again for your help, I read the tutorial in your signature, but go confused right when they dove it. Oh well one of these days I'll take a step-by-step method towards regex.
  3. Actually it works brilliantly now! Thanks a ton! By the way, is there a way I could pack this all into a method? I would do it right-off-the-bat but I don't know about the idea of a function inside the function (the callback) The current code I have follows: <?php $stage1 = "This is the free version, here you are #code#<?php echo \"This is the code\"; echo \"<br/>\"; echo \"and some more code\"; ?>#/code# And yeah lol"; function callback($src) { return "<div class='stylearoundcode'><br/>".htmlentities($src[1]) ."</div><br/>" ; } $stage1= preg_replace_callback("/#code#(.*)#\/code#/sm",'callback',$stage1); $stage1 = stripcslashes($stage1); echo "<pre>"; echo $stage1; echo "</pre>"; ?> Thanks again Sandeep!
  4. Thanks for the reply from both of you. Sandeep, yours has the more desired result with the pound signs (sorry playful I edited my post right when after you viewed it). However, Sandeep's outputs nothing as for now. Moving on, I want to replace the area where the code tags were with <div class=stylearoundcode> and </div>. From the div name, I just want to give them a nice box around it so that it can be distinguished from the rest of the user's post. Also, is there a way I could use brackets such as [ and ] instead of greater than and less than signs? Much like this site does?
  5. Hello everyone, I am an absolute novice when it comes to regex. I could learn it it strongly, but I need to spend much more time than I have. I am stuck with a problem where regex becomes a requirement. In short, I need to use regex to change code submitted by users to divs and htmlentities the code. I commented on the code because explaining there would make much more sense than explaining here. Anyways, it's much like this forum with the code tags. In my code, I've changed the code tags to have pound signs around them just so SMF won't think I'm posting more code inside a code tag. I'm sure there's an escape method, but here's the code: <?php //code outputted from database, I need to regex the code so that #code# is replaced by divs and the code is passed through htmlentities() $stage1 = "This is the free version, here you are #code#<?php echo \"This is the code\"; echo \"<br/>\"; echo \"and some more code\"; ?>#/code#"; //regex //how it should look after the regex process $stage2 = "This is a free version, here you are <div class=code>". htmlentities($regexed_code) . "</div>"; //get rid of slashes added by the mysql_real_escape_string() $stage3 = stripslashes($stage2); echo "<pre>"; echo($stage2); echo "</pre>"; ?> Thanks a lot! Sean
  6. Right, Thanks. This is what I was looking for.
  7. Thanks for the replies. I see what you mean, however there won't always be code in the user's reply. I only want to highlight the code when there is code.
  8. Basically, I'm trying to take a string from the db and do two things. [*]Prevent html from being processed as html (htmlspecialchars() i think) [*]Recognize PHP code and highlight it. This is a reply system much like what I'm typing right now. For example 2, I want to be able to do this <?php echo "hello"; ?> I've researched a little and found a function called highlight_php(). The problem I run into now is that I only want to highlight php when it is needed. I am stuck as to where to go next. My thoughts would be 2 regex functions, however I don't know which one to call first. Any suggestions? Everything is appreciated
  9. I took out the output buffering and that did nothing for me. I tried echoing text on the page index page, and it's not showing up. bizarre needless to say
  10. This error is very bizarre since I can't seem to debug it. When I require my header, it is included. When I require my footer, it is not. I am 100% the paths are correct, and I tried another file to make sure it wasn't the footer causing the error. Here's the code for the header, footer, and index. If you need to see anything else just tell me. header <?php ob_start(); ?> <?php ini_set('session.cookie_domain', '.domain'); ?> <?php ini_set('display_errors','On'); ?> <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <link rel='stylesheet' href='includes/css/reset.css' type="textcss"/> <link rel="stylesheet" href="includes/css/style.css" type="text/css"/> <title>Domain</title> </head> <?php require('classes/common.inc.php'); $common = new common(); if($common->_truesession()) { $hsuser = $_SESSION['username']; } $common->_cookiecheck(); $db = $common->_db(); echo "<ul>"; echo "<li><a href=domain.com>Domain</a><ul>"; $query = $db->_query("select * from links where id > 1"); while($row = $db->_assoc($query)) { $name = $row['name']; $link = $row['url']; echo "<li><a href=".$db->_out($link).">".$db->_out($name)."</a></li>"; } echo "</ul></li></ul>"; ?> index <?php require('includes/header.php'); ?> <?php ?> <?php require('includes/footer.php'); ?> footer <?php echo "<ul>"; echo "<li><a href=about.php>About</a></li>"; if(!$common->_truesession()) { echo "<li><a href=register.php>Register</a></li>"; } echo "</ul>"; $year = date('Y'); echo "&copy $year <a href='http://domain.com'>Domain</a>"; ob_end_flush(); ?>
  11. When I tried to add require('db.inc.php'); $db = new db(); at the beginning of the class I get syntax error, unexpected T_REQUIRE, expecting T_FUNCTION
  12. When I use another class inside one class, I get this error The code is here <?php require ('db.inc.php'); $db = new db(); class common { function _cookiecheck() { if(!isset($_SESSION['username'])) { if(isset($_COOKIE['username'])&&isset($_COOKIE['password'])) { $pass = $db->_safestring($_COOKIE['password']); $user = $db->_safestring($_COOKIE['username']); $check = _query("select password from users where username='{$user}'"); if($check) { $_SESSION['username'] = $user; } } } } } ?> I get the error on the line when I call $db->_safestring(); Thanks for the help
  13. thanks guys! Worked perfectly. I'll remember this for next time.
  14. Here's the code, I had used the query in the header, and now I'm using it to display the links in a table. What happens is that it only returns the first row and not the second third or fourth rows. When it does display the first row, it'll display it a lot of times. Here it is <?php if($_GET['place']==addnetwork){ //display current networks echo "<table border=1>"; echo "<tr><td>Network Name</td><td>URL</td></tr>"; while ($query1 = mysql_fetch_assoc(mysql_query("select name,url from s_links"))) { $networkname = $query1['name']; $networkurl = $query1['url']; echo "<tr><td>$networkname</td><td>$networkurl</td></tr>"; } echo "</table>"; } ?>
  15. html stacks, I want it to become in line, and when I use the display:inline-block; it doesn't work. How do I go about doing so?
×
×
  • 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.