Jump to content

Search the Community

Showing results for tags 'str_replace'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 10 results

  1. Can someone please tell me why neither one of these are working: $content = str_replace(array("\r", "\n"), '', $row['content']); $content = preg_replace( "/\r|\n/", '', $row['content']); I've tried each one of the to replace $content = $row['content']; and for some ungodly reason neither one of them are working. This is simply pulling content from a database but it keeps displaying \r\n when displayed in a page. Why?
  2. I'm having a probably server-side issue that I cannot fix, so I need to find a workaround. I have a page designed to allow people to enter their report and email it to a list of people (it will vary each time). There are 2 ways people can enter an email recipient: full email address or first and last name (which is how you find people in the corporate Outlook Exchange accounts). So when the recipient field is entered, it may contain a mix of full email addresses or just first and last names (separated by commas). For example, here's my original array of email recipients: $recipient = "bob.smith@abc.com, John Smith, Barb Johnson"; The problem is with the first and last names. When the email sends, it adds the entire domain of the server to the email address. For example, if the server I'm using is "test.server.xyz.com" and I enter "John Smith", when the email gets sent, it sends to "John.Smith@test.server.xyz.com" instead of just "John.Smith@xyz.com". So I'm wondering if there's code that would search an array using mixed email addresses, locate just the ones with first and last names, and fix them. How would I code this so it ended up as: $new_recipients = "bob.smith@abc.com, John.Smith@xyz.com, Barb.Johnson@xyz.com"; Thanks in advance! Note: I've asked IT if they can fix something on the server end to correct this, but I'm not counting on their help, so looking for a workaround.
  3. The situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it. For example: <?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?> This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!)
  4. Hi ; I have problem with search script ; This is code ; $search_form = "<form method='get' action='' ><span class='aktif'>Arama</span><input class='aktif' type='text' name='search' ><input class='aktif' type='submit'></form>"; echo $search_form ; $search = isset($_GET['search']) ? trim($_GET['search']): ''; $a1=(str_replace(' ', '',$search) ); $S1 = ' '; $S2 = ' '; $S3 = ' '; if($search != ''){ // Terimlerin Arama Kısmı $S1 = sprintf("WHERE Tetik_Ref like '%%%s%%' OR ",mysql_real_escape_string($search)); $S2 = sprintf("Marka_Model like '%%%s%%' OR",mysql_real_escape_string($search)); $S3 = sprintf("Orj_P_N like '%%%s%%'",mysql_real_escape_string($search)); } //Verilerin yazdırılma işlemi $main_query = "SELECT * FROM ats_motor $S1 $S2 $S3 "; $count_query = "SELECT COUNT(*) FROM ats_motor $S1 $S2 $S3 "; Orj_P_N column inside Original Part Numbers. Its same of "111 11 111" or "15K 1245 45" etc. When i search exact records work fine. But I search 11111111 nothing found. I search that and find str_replace function. But i cant use that. Cant import. I try change line 8 and 14. it give me error. Can anybody help me ? Thanks.
  5. Hi All, I'm trying to rename a category name from my url. Here it is: // Register custom post types add_action('init', 'pyre_init'); function pyre_init() { global $data; register_post_type( 'avada_portfolio', array( 'labels' => array( 'name' => 'Portfolio', 'singular_name' => 'Portfolio' ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => $data['portfolio_slug']), 'supports' => array('title', 'editor', 'thumbnail','comments'), 'can_export' => true, ) ); register_taxonomy('portfolio_category', 'avada_portfolio', array('hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true)); register_taxonomy('portfolio_skills', 'avada_portfolio', array('hierarchical' => true, 'label' => 'Skills', 'query_var' => true, 'rewrite' => true)); ... Here is what I have at the moment: function custom_portfolio_to_customer_category_url($content) { $current_path = 'portfolio_category'; $new_path = 'customer_category'; $content = str_replace($current_path, $new_path, $content); return $content; } add_filter('term_link', 'custom_portfolio_to_customer_category_url'); I'm using the str_replace() function to rename portfolio_category to customer_category. "It" did replace it but it seems to have wiped out the category and I'm unable to access the portfolio_category post. Can someone please guide me or assist me in what I'm doing wrong here? Thank you, Hal
  6. I have remade my company webpage using very little php mostly because I don't know it however the last web designer seemed to love it and now all the links that are out in the big www start with "?p=" and I can't do a 301 redirect on those pages. how do I rewrite those links as they are coming in to change ?p=page to page/php so I can properly redirect them in my htaccess file. Redirect 301 /?p=oldpage http://www.mypage.com/newpage.php/ won't redirect Redirect 301 /oldpage.php http://www.mypage.com/newpage.php/ will redirect I found this in his index.php file and I think thats what he used to change the .php to ?p= $page = (isset($_GET['p']) ? $_GET['p'] : $homePage); $page = basename($page); $page = str_replace(".php","",$page); if(!file_exists($page . '.php')){ $page = $errorPage;
  7. I'm using a form to capture various information - assigning the form input to PHP variables and then replacing placeholders in an external file with the appropriate PHP variables from the form using str_replace array - But, for some reason it replaces the first variable (specifically *bizname) in the external file correctly and then replaces the others with NULL / Blanks, as if the other form data isn't being stored in the variables - Any ideas why the other variables are not being replaces with data? form capture php file <form id="form1" method="post" action=""> <div>What is the advertised name of your business?<input name="busName" type="text" value="Enter Business Name" size="40" maxlength="40" style="margin-left:10px;" /></div> <hr /> <div>Enter the NUMERIC street number for your business:<input name="busNume" type="text" value="Enter Numeric Address" size="40" maxlength="40" style="margin-left:10px;" /></div> <div>Please select street direction:<select name="streetDir" size="1" style="margin-left:10px;"> <option>N</option> <option>E</option> <option>S</option> <option>W</option> <option> </option> </select></div> <div>Please enter the name of your street location:<input name="busStreet" type="text" value="Enter Street Name" size="40" maxlength="40" style="margin-left:10px;" /></div> <div>Please select the street type:<select name="streetType" size="1" style="margin-left:10px;"> <option>RD</option> <option>ST</option> <option>AVE</option> </select></div> <div>Enter your city:<input name="busCity" type="text" value="Enter City Name" size="40" maxlength="40" style="margin-left:10px;" /></div> <div>Enter your state:<select name="busState" size="1" style="margin-left:10px;"> <option>AL</option> <option>AK</option> <option>AZ</option> </select></div> <div>Enter your zip code: <input name="busZip" type="text" value="" size="10" maxlength="5" style="margin-left:10px;" /> </div> <hr /> <input type="submit" value="submit" > </form> PHP CODE in form capture file <?php $busName = $_POST["busName"]; $busNume = $POST["busNume"]; $stDir = $POST["streetDir"]; $busStreet = $POST["busStreet"]; $stType = $POST["streetType"]; $busCity = $POST["busCity"]; $busState = $POST["busState"]; $busZip = $POST["busZip"]; ?> <?php if (!empty($_POST)) { $myFile = "template.php"; $file_contents = file_get_contents($myFile); $fh = fopen($myFile, 'w') or die("can't open file"); $varibs = array('*bizname','*hn','*dir','*street','*stt','*busCity','*busState','*busZip'); $details = array($busName,$busNume,$stDir,$busStreet,$stType,$busCity,$busState,$busZip); $file_contents = str_replace($varibs,$details,$file_contents); fwrite($fh, $file_contents); fclose($fh); } ?> Last but not least the template PHP file being opened and written into (Just the relevant part - everything else stripped out) <div id="bname" class="bdetail bold fs19" itemprop="name">*bizname</div> <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress"> <div id="baddr" class="bdetail" itemprop='streetAddress'>*hn *dir *street *stt</div> <div id="bregion" class="bdetail" itemprop='addressLocality'>*busCity, <span itemprop='addressRegion'>*busState</span>*busZip <span itemprop='postalCode'></span></div>
  8. The application has to do with an alarm system. When an alarm event occurs it generates a 16 digit/character number and logs it on my linux server. I am trying to translate the code into english using str_replace. The problem i have is the last character/number is a checksum and changes so my search never comes up with a match. I got around this by just seaching the first 15 digits/characters even though the string is 16 digits/characters. This works and i have a valid match. Problem is once the replace happens, the 16th digit/character is showing up to the right of the replace. Question /Example 1: I can only search on the first 15 characters/digits of the 16 generated by the alarm The alarm generates the following string: 769418113401001A I execute the following line: file_put_contents($file,str_replace('769418113401001','769418113401001 Garage Kitchen Entry ',file_get_contents($file))); The output from the above line is: 769418113401001 Garage Kitchen Entry A How do I stop the 16th character/digit in this case "A" from showing up in the output????????????? Question/Example 2: I can only search on the first 10 characters/digits of the 16 generated by the alarm The alarm generates the following string: 7694181250123456 I execute the following line: file_put_contents($file,str_replace('7694181250','7694181250 Fire Alarm ',file_get_contents($file))); 7694181250 Fire Alarm 123456 How do i stop the last 6 digits/characters from showing up in the output? thanks for your help !!!!!!!
  9. Hi, I have created an array with symbols that I'd like to allow in a string of text. $symbols[] = '>'; // Greater Than or Open Angle Bracket $symbols[] = '<'; // Less Than or Close Angle Bracket $symbols[] = '/'; // Forward Slash $symbols[] = '\\'; // Back Slash $symbols[] = '&'; // Ampersand $symbols[] = '£'; // Pound Sterling $symbols[] = '$'; // Dollar $symbols[] = '\"'; // Quotation Marks $symbols[] = '\''; // Apostrophe $symbols[] = '#'; // Hash $symbols[] = ' '; // Space $symbols[] = '.'; // Period I would now like to use something like str_replace or preg_replace (whichever is best) to replace any character that is not included within the array $symbols with "". I know there are other ways to filter characters but it isn't a suitable solution considering who will be maintaining it... :-\ I'm hoping for something like; but obviously a working way. $myText = str_replace(!$symbols, "", $myText; $myText = preg_replace(!$symbols, "", $myText; Thank you for your help.
  10. Hi, I've been trying to remove a suborn <p> </p> which sometimes appears at the bottom of a database entry after the CMS in use strips out 'unsafe' HTML. The value returned from my SQL string is: (8, 'Title', 'Alias', '', '<p>My Paragraph</p>\r\n<p> </p>', '', 1); I've tried removing the unwanted <p> </p> using the code and find variations below, but still no success. $myIntro= $db->intro; $find = array('<p></p>','<p> </p>','<p> </p>',' ','\n'); $myIntro = str_ireplace($find,'', $myIntro); Does anyone have any other approaches to try and strip this out from my string? I can't dump all <p> tags as I still need the rest for formatting. Many thanks Matt
×
×
  • 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.