Jul 24, 2008

Help With Preg_replace

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Help With Preg_replace

galexcd
I must be a total noob, or just really tired...............-.- either way, I cannot understand what exactly those funky strings preg_replace wants for the pattern.

Could sombody explain to me exactly what the pattern string and the replace string in preg replace does?

I get str_replace... that's quite basic.

I considered myself a pro at php until tonight........haha shows how much i know. I bet tomorow, if i look it up I'll get it....

Anyway.. any help? Thanks..... laugh.gif

Reply

electron
It needs a regular expression as a pattern.
If you dont know that what are regular expressions it is quite simple to leasrn it. Just google it out OR go visit the php.net site where they have explained the whole function in details and read the comments below.
That help alot and have links to some great PHP related regular expressions.

But if you are using preg_replace to takecare of HTML tags or BBCODE it is useless.

Hope that helps

Reply

galexcd
Great help.. Thanks,

but why is it useless for bb code? because that's the reason I wanted to know.. Right now my message boards sorta suck because I'm using str_replace fore the bbcode, It's sorta annoying how you have to put url name every time, instead of also allowing http://www.mydomain.com.

I've also got a flash chat, and stupid flash's html has to be perfect, so <b><i>text</b></i> would leave the bold modifyer on. I was hoping for a way to use preg_replace to disable bbcode within bbcode for the chat.

Reply

electron
Well if you are using it for URL it is fine but make sure to make it ungreedy so that it matches not the whole thing but first start and first end.

Let me see if i have that for the URL stuff.

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*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : preg, replace

  1. A Simple Preg_replace Help Please.
    (1)
  2. Preg Replace Problem
    (1)
    If i have a word like c.........a......t (with the dots in) and i wanted to replace it with cat how
    would i do it. If i use CODE <?php $patterns =
    "/c(*)a(*)t/"; $replace = "cat"; echo
    preg_replace($patterns, $replace, 'c.....a.........t');
    [/color][color="#000000"]?> then when i type something like "
    c ome a nd look at t his" is also filtered. Is
    there any way just to filter cat with dots in? ....
  3. Unable To Replace .png File In Directory
    Can't even delete it using Cpanel (7)
    I can't delete a little file using file manager in Cpanel. I'm trying to delete a .png
    image, actually, I'm trying to replace it. The response comes back as a success, but when I
    reload my site it's still there. Then I go back to the file manager and go up a level, then back
    and WOOP! There it is! I'm beyond frustrated here. What is going on?....
  4. Php Preg Replace
    (1)
    Ive got a problem with preg replace, this is the code: display.php CODE <table
    border="1"> <tr><th width="70">Time</th><th
    width="200">IP</th><th
    width="70">Viewed</th></tr> <?php $LogData =
    file_get_contents("log.txt"); $Find =
    "/||(.*)|(.*)|(.*)||/i"; $Replace =
    "<tr><td>$1</td><td>$2</td><td>$3
    </td></tr>"; &#....
  5. Php Replace Help!
    (6)
    CODE <?php function code( $input ){ $data[0] = "<?php
    include(\"shoutbox.php?no="; $data[1] = "\");
    ?>"; $find[0] =
    "/\[b\](.*?)\[\/b\]/i";
    $find[1] =
    "/\[url\=(.*)\](.*)\[\/url\]/"
    ; $find[2] =
    "/\[u\](.*?)\[\/u\]/i";
    $find[3] = "/\&....
  6. How To Replace Japanese Cute Actor Face With Yours
    I'll teach you how to modified Japanese actor (or whoever) face by (1)
    This is my source pic, i label it as S . This is my handsome pic, i label it as O : First,
    i cut and paste my picture into the S picture. Turn low the opacity and fill and adjust the position
    so that it fit the S picture: Erase the unwanted area. Go to image-adjustment-brightness and
    contrast and adjust the lightning. Go to image-adjustment-color balance and adjust the color of O
    picture until you get harmonic tone. Repeat these steps until you get the desired colour. Mine look
    like this: Repeat all these steps until you get the best result. By com....
  7. Validation Script - Detecting Illegal Characters
    preg_match to find illegal characters (0)
    I'm trying to validate a user's desired username for a registration page. I want to detect
    any illegal characters being used for a username. So far i have managed to include most execpt the
    '\', the '\' is used for escape and treating the preceding characters
    literally. I try to do '\\' but i get an error because it execects another
    character. CODE $ck_result = "Default"; $pattern =
    "/[!|@|#|$|%|^|&|*|(|)|_|\-|=|+|\||,|.|\/|;|:|\'
    ;|\"|&#....
  8. 'red Devils' Replace Blues As Champions
    (0)
    QUOTE 'Red Devils' replace Blues as champions Manchester United regained the English
    Premiership title on Sunday after closest rivals Chelsea were held 1-1 by Arsenal. With two matches
    to play United, who last won the title four years ago, hold a seven-point advantage over Chelsea,
    who have won it for the past two seasons. United had beaten Manchester City 1-0 on Saturday thanks
    to a Cristiano Ronaldo penalty - his 23rd goal of the season - and Chelsea were up against it when
    they went 1-0 down and lost Khalid Bouhlarouz - who was sent-off - in the first-....
  9. Preg_replace Problems
    (7)
    Sigh... preg_replace is getting very annoying for me. Could sombody tell me what I'm doing
    wrong? Im making a bbcode replace for the forums I made, and preg_replace is being a b****...
    Right now Im working on the tag, and I want to check for valid URL's, because idiots in the
    forum are adding js and stuff in the image tags and messing it all up. So i put a function in the
    array that holds all of the replacements: CODE
    $main_search=array('/\[b\](.*?)\[\/b\]
    /is','/\[i\ ....
  10. Replace A Character In A Specific Tag
    (7)
    I need a code that replaces all spaces between ] brackets with an underscore. So, basically, I
    write this into a variable: CODE bla bla something [[some text]] more text here
    And I want a script to change it to this: CODE bla bla something [[some_text]]
    more text here Any suggestions?....
  11. Regexp Function Preg_match_all()
    preg_match_all() - Help me (0)
    Hi, I got a new problem which has caused me to go mad but no solution. preg_match_all() - is the
    problem. I have something like this: CODE [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] [/ol] Some text.Some text.Some text. [ol]
    [li]Test1[/li] [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] &....
  12. Wmp (windows Media Photo) - The New Image File Format From Microsoft
    windows media photo WMP - could replace JPGs and GIFs? (31)
    Microsoft have decided to come up with a new image format to add to the common JPGs, GIFs and PNGs
    of today. It is to be called Windows Media Photo format or WMP for short. It is said to
    "Surpass the limitations of existing file formats" and here is what it'll offer: Numerous
    colour formats for printing and displaying High-quality lossy or even lossless compression
    Really efficient decoding for numerous resolutions For more features, visit
    http://www.microsoft.com/whdc/xps/wmphoto.mspx Presumeably, the JPEG2000 format or JP2 was
    ....
  13. Php Preg_match_all() Fails
    (2)
    I checked phpinfo() and --with-pcre-regex=/usr is setup there in the compile options, so why it
    shouldn't work I dunno. The array always returns empty. The Posix regex seem to work btw.....
  14. How To Replace A Cd-rom Drive In A Pc
    (3)
    Hi, Im going to teach you how to replace a CD-Rom drive in a PC. It just takes a few simple steps
    to do this, it is really not that hard. You can trust me since I have an a+ certification in
    computer hardware and software. I know what I am doing, I am an expert. 1. First of all, you need
    to shut off your computer. To do this press the power button on the front of the computer after you
    have shut it down from Start> Shutdown on your start menu. 2. Unplug the power cord from your
    computer. This is the big black/white/grey plug that plugs into the power supply on the bac....
  15. How To Replace Ram In Your Pc
    (0)
    Hello everyone, This is how to replace RAM in a PC. It just takes a few simple steps to do this, it
    is really not that hard. You can trust me since I have an a+ certification in computer hardware and
    software. I know what I am doing, I am an expert. 1. First of all, you need to shut off your
    computer. To do this press the power button on the front of the computer after you have shut it down
    from Start> Shutdown on your start menu. 2. Unplug the power cord from your computer. This is the
    big black/white/grey plug that plugs into the power supply on the back of your PC.....
  16. Bush Nominate Roberts As Chief Justice
    One conservative to replace another? (1)
    It's hard to believe that the Chief Justice is no longer William Rehnquist. He was the answer to
    the citizenship exam question: Who is the Chief Justice of the US Supreme Court? Ans: William
    Rehnquist. Wow... Personally, I think Bush brings death to his people in a karma-like way. So many
    people have died during his terms already. Just think, during Bush's reign all kinds of natural
    disasters occured (hurricanes, tsunamis), war, terrorist attacks, Supreme Court Justices died...Of
    course, I'm not saying that Bush wants these things to happen or is directly re....
  17. Help With Reading Files
    Read and replace/insert data from form (5)
    Hi, Does anyone know how i can do this, or scripts that will work on Trap17's servers and will
    do the following: I have a .doc file form. Which i want to have filled in automactically, by HTML
    Form and emailed to my address, with the data filled in. Any ideas? I have heard many differing
    things, like XML, RTF, DOC, PDF... I have serched through many places and come up empty handed with
    anything that works. /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' /> ....
  18. Help With Uploading Index File
    i cannot remove rename edit or replace (6)
    When I try to edit, remove, rename, or replace my index into my public_html folder. It does not
    work. Is there anyway to erase everything on your account, and start from scratch. Or a way to fix
    this problem. I have PMed and Emailed the admin but haven't gotten help, can anyone here help
    me?....
  19. Replace Shtml With Php?
    I don't know jack.... (1)
    I don't know anything about PHP, except that I use phpBB and have modified my forums template
    files. I used to make web sites years ago and just got back into it a couple months ago. I wonder
    if I should stop using shtml and switch to php. I don't really have time to learn php (at least
    not yet), but if it's easy to replace my Server Side Include with php (just to be more "modern")
    I would be willing to do so. Anyone have any suggestions about me doing so? Am I'm too old
    school for using shtml? Lol /laugh.gif' border='0' style='vertical-align:middle' ....

    1. Looking for preg, replace

Searching Video's for preg, replace
advertisement



Help With Preg_replace



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE