PHP - Moved: Preg Replace Help
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=351288.0 Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=321641.0 $name = preg_replace('{(\d+)}', convertNumber("$1"), $row['name']); why isnt this working? basically what i am trying to do is replace the <a href="whatever.com"> with <a href="whatever.com" onclick = "if (! confirm("Continue?")) return false;"> so that when the user clicks the url in a message the box pops up first then redirects them to the url if they click confirm. However i am getting the following error: Code: [Select] Warning: preg_replace() [function.preg-replace]: Compilation failed: reference to non-existent subpattern at offset 11 here is the code i used. $message_content = $content_info['message_content']; $pattern='<a href="\\1">'; $replace='<a href="\\1" onclick = "if (! confirm("Continue?")) return false;">'; $message_content = preg_replace($pattern, $replace, $message_content); echo $message_content; Anyone know where i went wrong? So i have this script that outputs Listed Files inside a folder echo '<option value="'.$fileName.'">'.$fileName.'</option>';} like this : <option value="Fonts/28 Days Later.ttf">Fonts/28 Days Later.ttf</option> etc files .... i would like to know how may i remove " Fonts/ " And the .ttf extension from the second part that repeats (the name) using something like preg_replace and to make the first letter uppercase using ucfirst() And if someone is familiar with preg_replace could you please give me a tutorial on how it works to replace some text ? Thanks In Advance im having trouble using this function. im trying to change the strings within a post. eg: Code: [Select] This is an example post [attachment=file.png] what im trying to do is change [attachment=file.png] to file.png. Here is the code i have but it doesnt change anything. $p_content = str_replace('<br>', '', $post_info[$key]['p_content']); $attach = preg_split('|\[attachment=|', $p_content); for($i=0; $i<count($attach); $i++) { $attach[$i] = str_replace(']', '', $attach[$i]); if(file_exists($config['asf_root'].'attachments/'.$attach[$i])) { $p_content = preg_replace('|\[attachment=([0-9a-zA-Z\.-_])\]|#i', $attach[$i], $p_content); } } echo $p_content; it first gets all the attachment tags within the post then applies the preg replace to all of them. But the preg replace isnt replacing, so i must have gone wrong somewhere. Any tips/ideas? Thanks Code: [Select] $text = preg_replace('{-(\d+)}e', '-convertNumber("$1")', $text); i have strings im trying to replace like this: name-2 > name-two name-p2 > name-p2 im trying to match and replace the first one and basically ignore the second one. ive included the hyphen in the code. so why isnt this working? i keep getting this at top of page Warning: preg_replace() [function.preg-replace]: No ending delimiter '`' found in C:\xampp\htdocs\socialtscripts\activation.php on line 16 here is the code that it is reffering to Code: [Select] preg_replace("`", "", $id); Hi, I am having a pretty difficult time getting files to upload to my server that have a Single Quote in the file name. Example: myfile's.pdf I need to strip the file name of the quote before it uploads to the server. I currently am using SWFUpload and this is the bit of code that was included with it. I need to modify it to remove the single quotes as well. Been hammering my head over this all day. $file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name'])); if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) { HandleError("Invalid file name"); exit(0); } thanks I've never really made my own bbcode parser function before, but I'm going off of different tutorials to help me create my own style of parsing. I've actually never really used preg_replace much, either. My code is returning an odd error and I have no idea how to fix it. I'm using codeigniter and the error it returns is below: Quote preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 6 This is the code for my function: Code: [Select] function bbParse($string){ $codes = array( '/\[b\](*?)\[\/b\]/' => '<b>\\1</b>', //bold tags '/\[h2\](*?)\[/h2\]/' => '<h2>\\1</h2>', //h2 tags '/\[h3\](*?)[\/h3\]/' => '<h3>\\1</h3>', //h3 tags '/\[quote\](*?)\[\/quote\]/' => '<blockquote>\\1</blockquote>', //quote tags using the template's blockquote tag '/\[img\](*?)\[/img\]/' => '<img src=\'\\1\' alt=\'Image Not Available\'>', //image tags '/\[url\=(*?)\](*?)\[/url\]/' => '<a href=\'\\1\' title=\'\\2\'>\\2</a>', //anchor tags '/\[p\](*?)\[/p\]/' => '<p>\\1</p>' //paragraph tags ); $string = preg_replace(array_keys($codes), array_values($codes), $string); return $string; } Code: [Select] line 129- function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $bad_words= $row['badwords']; $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words); $spaced_bad_words = trim($spaced_bad_words); $str = preg_replace("/$bad_words | $spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str); } return $str; Line 143 - } I go this error "Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in C:\xampp\htdocs\login\chatlog3.php on line 139" i get the following error in the comments in wordpress blog..: Warning: preg_replace() [function.preg-replace]: No ending delimiter '~' found in /home/doughhhh/public_html/wp-content/themes/upload/includes/theme-comments.php on line 75 the content of the file is: Code: [Select] <?php // Fist full of comments if (!function_exists("custom_comment")) { function custom_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?>> <a name="comment-<?php comment_ID() ?>"></a> <div id="li-comment-<?php comment_ID() ?>" class="comment-container"> <div class="comment-head"> <?php if(get_comment_type() == "comment"){ ?> <div class="avatar"><?php the_commenter_avatar($args) ?></div> <?php } ?> <div class="reply"> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> </div><!-- /.reply --> </div><!-- /.comment-head --> <div class="comment-entry" id="comment-<?php comment_ID(); ?>"> <span class="arrow"></span> <div class="comment-info"> <div class="left"><span class="name"><?php the_commenter_link() ?></span></div> <div class="right"> <span class="date"><?php echo get_comment_date(get_option( 'date_format' )) ?> <?php _e('at', 'themejunkie'); ?> <?php echo get_comment_time(get_option( 'time_format' )); ?></span> <span class="perma"><a href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'themejunkie'); ?>">#</a></span> <span class="edit"><?php edit_comment_link(__('Edit', 'themejunkie'), '', ''); ?></span> </div> <div class="clear"></div> </div> <?php comment_text() ?> <?php if ($comment->comment_approved == '0') { ?> <p class='unapproved'><?php _e('Your comment is awaiting moderation.', 'themejunkie'); ?></p> <?php } ?> </div><!-- /comment-entry --> </div><!-- /.comment-container --> <?php } } // PINGBACK / TRACKBACK OUTPUT if (!function_exists("list_pings")) { function list_pings($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li id="comment-<?php comment_ID(); ?>"> <span class="author"><?php comment_author_link(); ?></span> - <span class="date"><?php echo get_comment_date(get_option( 'date_format' )) ?></span> <span class="pingcontent"><?php comment_text() ?></span> <?php } } if (!function_exists("the_commenter_link")) { function the_commenter_link() { $commenter = get_comment_author_link(); if ( preg_match( '~]* class=[^>]+>~', $commenter ) ) {$commenter = preg_replace( '~(]* class=[\'"]?)~', '\\1url ' , $commenter ); } else { $commenter = preg_replace( '~(<a )/', '\\1class="url "~' , $commenter );} echo $commenter ; } } if (!function_exists("the_commenter_avatar")) { function the_commenter_avatar($args) { $email = get_comment_author_email(); $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( "$email", $args['avatar_size']) ); echo $avatar; } } ?> help! [attachment deleted by admin] This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=311437.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=310802.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=354568.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=331482.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=311251.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345772.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326673.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=328966.0 |