Php Any Variable In String.

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Php Any Variable In String.

sparkx
OK well I am making a new php program and I am trying to add bbcode to it. Anyway I was going to replace each thing by it self, but that could cause errors. Anyway is there a way to make a variable be anything? Here is an example:
CODE
This is the bbcode:
[color=00FF00]Hey[/color]
In my php:
$bbcode = array("[color=".$a."]");
$html = array( "<font color='#".$a."'>");
$topic_content = str_replace($bbcode, $html, $posted_bbcode);

So I want $a to be any variable but the same variable as used before. Do you get what I am saying? It is a little confusing but basicly what is the best way to make bbcode? It may not even involve the str_replace but this was the easyiest way to explain what I wanted.

Thanks for everyone that helps,
Sparkx

Reply

Quatrux
It can be done in several ways, but as for your problem, I think you could just use a regular expression, even though I like to avoid them, I never got into regular expressions, just found them or asked for them on IRC channels, you would need to use preg_replace(); read on it on the php manual wink.gif

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Similar Topics

Keywords : php, variable, string,

  1. Permanent Variable
    (7)
  2. Send Php Variable To Javascript
    (5)
    Right i had a look across the internet as well as a search on here but you cannot search for
    anything less than 3 characters. But this is a really quick question. Would the following code
    allow me to send a php variable to a javascript? CODE $color = "green"; ?> BackColor= " ";
    ....
  3. Unexpected Error
    Undefined variable??? (2)
    Is this script correct? index.php : CODE     if (isset($_COOKIE ))           $_GET =
    $_COOKIE ;     else         setcookie("disp_name", Anonymous, date()+99); ?>              
    Display Name - DZN                                                                   
                    Dislpay Name: name="name" />                                                
         proccess.php : CODE      Proccessing Request...           Please wait...
        setcookie("disp_name", $_GET , date()+99); ?> main.php : CODE     function customErr....
  4. Quickly Create Form Variables
    simple form, variable creation, referer check, safe guard variables (5)
    The reason I wanted to share this is I've seen so many people do this with their forms when
    using PHP. CODE $username = $_POST ; $password = sha1($_POST ); $another_var = $_POST ; ...
    and so on, just imagine if you had a large number of form inputs, do you really want to create each
    and every variable name? Why people do this, is probably due to most of the examples I've seen
    on the web, that does not show an easier and much quicker way of doing it. Though my way might be
    much easier and quicker, it does introduce security concerns which I've tried....
  5. Variable From Line Further Then Current Line?
    (13)
    Hello, Is it in some way possible to load a variable that further then the current line in the
    script? I don't know if you know what i mean so I'll try to point it out in the script
    below. CODE 1 2      echo $var1; 3      # $var1 needs to be loaded from foo.php 4     # Lets
    say i want $var1 to be echoed in $var1 5       - - - -       bla bla bla 55      - - - -
    56      switch($_GET ) { 57          case "foo": 58              include("foo.php");
    59              #- - - - from foo.php - - - - 60                   $var1 = "what ever you want";
    61           ....
  6. How To Reset The Server Variable Php_auth_user
    (9)
    Hi, i'm developing a web application which obviously requires a log in/log out script that i
    just implementing but i dont know why the log out script dont work fine. The problem is related
    with the server variable $_SERVER which remains set even when in the log out script i unset it with
    the unset() function. Does someone knows how can i reset or clear the server variable $_SERVER ???
    Best regards, ....
  7. Help: $_post Variable For Options From Select Types?
    (6)
    I want to know if there is a way to get the variables in $_POST for the options (not just the
    selected ones, but the unselected ones as well) of a type. Objective: Creating an application for
    my school. Issue: I am successful in receiving all the variables from the forms except the ones
    added to the options of a type. Just wanted to know what is the variable to access the options of
    types. Here is what I am trying to do with it: View Page If the server is down or unable to
    load file, here is the script: CODE      Malden High School va....
  8. Php Variable Concatenation
    Something New I learned Today! :P (7)
    I was coding one of my php page today, when I realized that I had to add multiple values to a
    variable (now that I think of it, a solution with arrays is possible too). But, the problem is that
    I have to add them in different parts of the code, so the new line that defines the variable will
    cover up the previous one. I played around with the code, and I finally got this solution:
    $message = "test1"; $message .= "test2"; $message .= "test3"; echo $message; By adding a dot in
    front of the = sign, I could concatenate the previous value with the new one and put them i....

    1. Looking for php, variable, string,






*SIMILAR VIDEOS*
Searching Video's for php, variable, string,
advertisement




Php Any Variable In String.