spires Posted December 15, 2008 Share Posted December 15, 2008 Hi guys, I have this tool that i'm building, it's basically a big form. What i've added is a feature that allows me to insert values from another field. Example: input field = include [[ext]] Extension field = extension term 1 The out put for input field will echo: include extension term 1 This work fine, however, if root field has multiple values, then the output include a \n after the [[ext]] Can some one please help? Here's the website: http://adwordssupremacy.com/standard.php - fill in all fields - Generate adtext selected - add at least 2 values in root terms and extension terms - add [[ext]] inside the Campaign Name feild - Generate the results. You will see in the results output box, a \n has been added after the [[ext]] Here is the code: function generate_adgroup_ext_text(&$vars, &$keyword_array, &$adgroup_array) { $adgroup_ext_text = ""; // init string to return // Count $count_row = '0'; // cycle through adgroup array and generate string foreach ($adgroup_array as $adgroup) { $adgroup = trim($adgroup); // From if ($vars['checkbox_from']) $came_from = '&fm=' . $vars['from_value']; // End From // Tracker $key_id = ""; if ($vars['checkbox_tracking_id']) { if ($vars['$tracking_id_value']) $key_id .= "?" . $vars['tracking_id_value'] . "={KeyWord}"; else $key_id = "?kw={KeyWord}"; } // END Tracker // ROOT Keyword Insertion if (strpos($vars['campaign_name'], '[[root]]')) { $campaign_name_insertion = str_replace('[[root]]', $adgroup, $vars['campaign_name']); } elseif (strpos($vars['campaign_name'], '[[ext]]')) { $campaign_name_insertion = str_replace('[[ext]]', $keyword_array[$count_row], $vars['campaign_name']); } else { $campaign_name_insertion = $vars['campaign_name']; } $headline_insertion = str_replace('[[root]]', $adgroup, $vars['headline']); $body1_insertion = str_replace('[[root]]', $adgroup, $vars['body1']); $body2_insertion = str_replace('[[root]]', $adgroup, $vars['body2']); $display_url_insertion = str_replace('[[root]]', $adgroup, $vars['display_url']); $destination_url_insertion = str_replace('[[root]]', $adgroup, $vars['destination_url']); // End Keyword Insertion if ($vars['adgroup_ext']) { if ($vars['adgroup_ext_placement'] == 'EXT_before') $adgroup_ext_text .= $campaign_name_insertion . ", " . $vars['adgroup_ext'] . " $adgroup, "; else $adgroup_ext_text .= $campaign_name_insertion . ", $adgroup " . $vars['adgroup_ext'] . ", "; $adgroup_ext_text .= $vars['headline'] . ", " . $vars['body1'] . ", " . $vars['body2'] . ", " . $vars['display_url'] . ", " . $vars['destination_url'] . "$key_id$came_from\n"; } else { $adgroup_ext_text .= $campaign_name_insertion . ", $adgroup, " . $vars['headline'] . ", " . $vars['body1'] . ", " . $vars['body2'] . ", " . $vars['display_url'] . ", " . $vars['destination_url'] . "$key_id$came_from\n"; } $count_row += 1; } return $adgroup_ext_text; // return completed results string } Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/ Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 trim $val = trim($val, "\n"); or str_replace $val = str_replace("\n", "", $val); Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/#findComment-716175 Share on other sites More sharing options...
spires Posted December 15, 2008 Author Share Posted December 15, 2008 Hi I've added: $key_trim = trim($keyword_array[$count_row], "\n"); but it's still not doing nothing. Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/#findComment-716192 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 Hi I've added: $key_trim = trim($keyword_array[$count_row], "\n"); but it's still not doing nothing. Are you sure it is only a "\n" and not a "\r\n" or vice versa? $key_trim = trim($keyword_array[$count_row], "\r\n"); I think that would/should work if that is the case. Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/#findComment-716193 Share on other sites More sharing options...
spires Posted December 15, 2008 Author Share Posted December 15, 2008 To be honest, i'm not sure what it is. It happens when I hit the return key. I've just tried \r and \n and \r\n. Nothing. Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/#findComment-716200 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 Just curious have you tried str_replace also? As I believe trim only removes it from the end or beginning of the string (not sure of this though). Quote Link to comment https://forums.phpfreaks.com/topic/137112-how-to-remove-a-line-break/#findComment-716202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.