str_replace(); funktioniert nicht richtig

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • str_replace(); funktioniert nicht richtig

    Hallo Zusammen.

    Ich habe das Problem das bei diesem Script nicht alle URL geändert werden. Einiges Funktioniert.. aber nicht alles?

    PHP-Quellcode

    1. ​function mfn_migrate_cb(){
    2. global $wpdb;
    3. $safety_limit = 6;
    4. if( key_exists( 'mfn_migrate_nonce',$_POST ) ) {
    5. if ( wp_verify_nonce( $_POST['mfn_migrate_nonce'], basename(__FILE__) ) ) {
    6. $old_url = stripslashes(htmlspecialchars($_POST['old']));
    7. $new_url = stripslashes(htmlspecialchars($_POST['new']));
    8. if( strlen($old_url) < $safety_limit || strlen($new_url) < $safety_limit ){
    9. echo '<p><strong>For your own safety please use URLs longer than '. $safety_limit .' characters !</strong></p>';
    10. } elseif( strpos( $old_url, 'http' ) !== 0 || strpos( $new_url, 'http' !== 0 ) ){
    11. echo '<p><strong>URLs must begin with http:// or https:// !</strong></p>';
    12. } else {
    13. $results = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta
    14. WHERE `meta_key` = 'mfn-page-items'
    15. " );
    16. if( is_array( $results ) ){
    17. // print_r($results);
    18. // posts loop -----------------
    19. foreach( $results as $result_key=>$result ){
    20. $meta_id = $result->meta_id;
    21. $meta_value = unserialize(base64_decode($result->meta_value));
    22. // print_r($meta_value);
    23. // sections loop ----------------
    24. foreach( $meta_value as $sec_key=>$sec ){
    25. // section attr loop ----------------
    26. foreach( $sec['attr'] as $attr_key=>$attr ){
    27. $attr = str_replace($old_url, $new_url, $attr);
    28. $meta_value[$sec_key]['attr'][$attr_key] = $attr;
    29. }
    30. // items loop ----------------
    31. foreach( $sec['items'] as $item_key=>$item ){
    32. // meta fields loop ----------------
    33. foreach( (array)$item['fields'] as $field_key=>$field ){
    34. $field = str_replace($old_url, $new_url, $field);
    35. $meta_value[$sec_key]['items'][$item_key]['fields'][$field_key] = $field;
    36. }
    37. }
    38. }
    39. // print_r($meta_value);
    40. $meta_value = base64_encode(serialize($meta_value));
    41. $wpdb->query( "UPDATE $wpdb->postmeta
    42. SET `meta_value` = '". addslashes($meta_value) ."'
    43. WHERE `meta_key` = 'mfn-page-items'
    44. AND `meta_id`= ". $meta_id ."
    45. ");
    46. }
    47. }
    48. echo '<p><strong>All done. Have fun!</strong></p>';
    49. }
    50. } else {
    51. echo '<p><strong>Invalid Nonce !</strong></p>';
    52. }
    53. }
    54. ?>
    55. <div class="wrap">
    56. <div id="icon-tools" class="icon32"></div>
    57. <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
    58. <br />
    59. <form action="" method="post">
    60. <input type="hidden" name="mfn_migrate_nonce" value="<?php echo wp_create_nonce(basename(__FILE__)); ?>" />
    61. <label style="width:50px; display:inline-block;">Find</label>
    62. <input type="text" name="old" value="" placeholder="Old URL" style="width:300px;" />
    63. <br />
    64. <label style="width:50px; display:inline-block;">Replace</label>
    65. <input type="text" name="new" value="<?php echo home_url(); ?>" style="width:300px;" />
    66. <input type="submit" name="submit" class="button button-primary" value="Replace" />
    67. </form>
    68. </div>
    Alles anzeigen

    Was könnte das Problem sein?
  • Ja.
    Z.B. hier klappt es wunderbar

    Quellcode

    1. ​ )
    2. )
    3. [open1st] =&gt; 1
    4. )
    5. )
    6. [1] =&gt; Array
    7. (
    8. [type] =&gt; column
    9. [size] =&gt; 1/3
    10. [fields] =&gt; Array
    11. (
    12. [title] =&gt;
    13. [content] =&gt; <h4 class="title">HIGHLIGHTS</h4>
    14. <!-- beginn autotemp x5f15 -->
    15. <div>
    16. <div class="team" ontouchstart="this.classList.toggle('hover');">
    17. <div class="flipper"><div class="flipper_wrapper">
    18. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_bmw_x5_news1.jpg" width="100%" alt="BMW X5 F15 BY HAMANN">
    19. </div>
    20. <div class="photo">
    21. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_bmw_x5_news1.jpg" width="100%" alt="BMW X5 F15 BY HAMANN">
    22. </div>
    23. <div class="desc">
    24. <table>
    25. <tbody><tr><td><h5>DER NEUE X5 BMW</h5><p class="subtitle">BY HAMANN</p><div>[button2 link="http://localhost/novads/hamann/bmw/f15/" title="Ansehen" size="small" color="orange"] [button2 link="#" title="Download" size="small" color="red"]</div></td></tr></tbody></table></div></div></div>
    26. </div>
    27. <!-- beginn autotemp x5f15-->
    28. <!-- beginn autotemp Lambo -->
    29. <div>
    30. <div class="team" ontouchstart="this.classList.toggle('hover');">
    31. <div class="flipper"><div class="flipper_wrapper">
    32. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_lambo_nervudo_news.jpg" width="100%" alt="LAMBO">
    33. </div>
    34. <div class="photo">
    35. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_lambo_nervudo_news.jpg" width="100%" alt="LAMBO">
    36. </div>
    37. <div class="desc">
    38. <table>
    39. <tbody><tr><td><h5>LAMBORGHINI AVENTADOR</h5><p class="subtitle">NERVUDO FÜR LAMBO AVENTADOR BY HAMANN</p><div>[button2 link="http://localhost/novads/hamann/lamborghini/nervudo-fuer-aventador/" title="Ansehen" size="small" color="orange"] [button2 link="#" title="Download" size="small" color="red"]</div></td></tr></tbody></table></div></div></div>
    40. </div>
    41. <!-- beginn autotemp Lambo-->
    42. <!-- beginn autotemp 4er -->
    43. <div>
    44. <div class="team" ontouchstart="this.classList.toggle('hover');">
    45. <div class="flipper"><div class="flipper_wrapper">
    46. <a href="http://localhost/novads/hamann/bmw/f32/">
    47. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_bmw_4er_news.jpg" width="100%" alt="BMW 4ER BY HAMANN"></a>
    48. </div>
    49. <div class="photo">
    50. <a href="http://localhost/novads/hamann/bmw/f32/">
    51. <img src="http://localhost/novads/wp-content/uploads/2014/02/hamann_bmw_4er_news.jpg" width="100%" alt="BMW 4ER BY HAMANN"></a>
    52. </div>
    53. <div class="desc">
    54. <table>
    55. <tbody><tr><td><h5>DER NEUE 4ER BMW</h5><p class="subtitle">BY HAMANN</p><div>[button2 link="http://localhost/novads/hamann/bmw/f32/" title="Ansehen" size="small" color="orange"] [button2 link="#" title="Download" size="small" color="red"]</div></td></tr></tbody></table></div></div></div>
    56. </div>
    57. <!-- beginn autotemp 4er-->
    58. )
    59. )
    60. )
    61. )
    Alles anzeigen
  • Hier klappt es nur zum Teil.

    Quellcode

    1. ​Array
    2. (
    3. [0] =&gt; Array
    4. (
    5. [attr] =&gt; Array
    6. (
    7. [bg_image] =&gt;
    8. [bg_position] =&gt; no-repeat;center top;;
    9. [bg_color] =&gt;
    10. [layout] =&gt; no-sidebar
    11. [sidebar] =&gt; 0
    12. [padding_top] =&gt; 0
    13. [padding_bottom] =&gt; 0
    14. [class] =&gt;
    15. )
    16. [items] =&gt; Array
    17. (
    18. [0] =&gt; Array
    19. (
    20. [type] =&gt; column
    21. [size] =&gt; 1/1
    22. [fields] =&gt; Array
    23. (
    24. [title] =&gt;
    25. [content] =&gt; <h2 class="title">Gallery</h2>
    26. [gallery link="file" columns="5" ids="10472,10473,10474,10475,10476,10477,10478"]
    27. )
    28. )
    29. [1] =&gt; Array
    30. (
    31. [type] =&gt; tabs
    32. [size] =&gt; 1/1
    33. [fields] =&gt; Array
    34. (
    35. [count] =&gt; 6
    36. [tabs] =&gt; Array
    37. (
    38. [0] =&gt; Array
    39. (
    40. [title] =&gt; LEICHTMETALLRÄDER
    41. [content] =&gt; <style>
    42. .product-list {
    43. overflow:hidden;
    44. text-align:center;
    45. padding:7px 0 14px;
    46. }
    47. .product-list ul {
    48. list-style:none;
    49. margin:0;
    50. padding:0;
    51. overflow:hidden;
    52. display:inline-block;
    53. vertical-align:top;
    54. width:850 px;
    55. }
    56. *+html .product-list ul {display:inline;}
    57. .product-list li {
    58. float:left;
    59. width:138px;
    60. padding:0 30px 20px 0;
    61. }
    62. /*.product-list li:first-child {padding:0;}*/
    63. a {
    64. color:#232323;
    65. cursor:pointer;
    66. }
    67. .product-list a:hover {text-decoration:none;}
    68. .product-list img {
    69. display:block;
    70. margin:0 0 13px;
    71. }
    72. .product-list .info-text {
    73. display:block;
    74. overflow:hidden;
    75. border:solid #000;
    76. border-width:1px 0;
    77. padding:8px 0;
    78. }
    79. .info-text span {
    80. display:block;
    81. text-transform:uppercase;
    82. line-height:13px;
    83. padding:0 0 4px;
    84. }
    85. .info-text strong {
    86. display:block;
    87. font:14px/16px 'Oswald', Arial, Helvetica, sans-serif;
    88. text-transform:uppercase;
    89. }
    90. </style>
    91. <h4 class="title">Hamann Felgenprogramm</h4>
    92. <!-- beginn autotemp x5f15 -->
    93. <div class="product-list">
    94. <ul>
    95. <li><a href="http://ds.novart.biz/wp-content/uploads/hamann/felgen/html/edition_race_andoized.html?iframe=true&amp;width=70%&amp;height=100%" rel="prettyPhoto[iframes]" title="HAMANN EDITION RACE ANODIZED, BESTELLNUMMER &amp; E-MAIL +41627217324 INFO@DS-AUTOMOBILE.CH"><img src="http://ds.novart.biz/wp-content/uploads/hamann/felgen/img/ED_ANO_01.jpg" width="138" height="160" alt=""><span class="info-text"><span>Edition Race</span><strong>"Anodized"</strong></span></a></li>
    96. <li><a href="http://ds.novart.biz/wp-content/uploads/hamann/felgen/html/edition_race_matt_black.html?iframe=true&amp;width=70%&amp;height=100%" rel="prettyPhoto[iframes]" title="EDITION RACE MATT BLACK, BESTELLNUMMER &amp; E-MAIL +41627217324 INFO@DS-AUTOMOBILE.CH"><img src="http://ds.novart.biz/wp-content/uploads/hamann/felgen/img/ER-MATT.jpg" width="138" height="160" alt=""><span class="info-text"><span>Edition Race</span><strong>"Matt Black"</strong></span></a></li>
    97. <li><a href="http://ds.novart.biz/wp-content/uploads/hamann/felgen/html/unique_forged_gunmetal.html?iframe=true&amp;width=70%&amp;height=100%" rel="prettyPhoto[iframes]" title="UNIQUE FORGED GUNMETAL, BESTELLNUMMER &amp; E-MAIL +41627217324 INFO@DS-AUTOMOBILE.CH"><img src="http://ds.novart.biz/wp-content/uploads/hamann/felgen/img/UF-GUN.jpg" width="138" height="160" alt=""><span class="info-text"><span>Unique Forged</span><strong>"Gunmetal"</strong></span></a></li>
    98. </ul>
    99. </div>
    100. )
    101. [1] =&gt; Array
    102. (
    103. [title] =&gt; ACCESSOIRES
    104. [content] =&gt; <h4 class="title">Hamann Accessoires</h4>
    105. <h6>Inhalt folgt in kürze für Infos +41 62 721 73 24</h6>
    106. )
    107. [2] =&gt; Array
    108. (
    109. [title] =&gt; AUSPUFFANLAGEN
    110. [content] =&gt; <h4 class="title">Hamann Accessoires</h4>
    111. <h6>Inhalt folgt in kürze für Infos +41 62 721 73 24</h6>
    112. )
    113. [3] =&gt; Array
    114. (
    115. [title] =&gt; MOTORTUNING
    116. [content] =&gt; <h4 class="title">Hamann Accessoires</h4>
    117. <h6>Inhalt folgt in kürze für Infos +41 62 721 73 24</h6>
    118. )
    119. [4] =&gt; Array
    120. (
    121. [title] =&gt; AERODYNAMIK
    122. [content] =&gt; <h4 class="title">Hamann Accessoires</h4>
    123. <h6>Inhalt folgt in kürze für Infos +41 62 721 73 24</h6>
    124. )
    125. [5] =&gt; Array
    126. (
    127. [title] =&gt; BREMSANLAGEN
    128. [content] =&gt; <h4 class="title">Hamann Accessoires</h4>
    129. <h6>Inhalt folgt in kürze für Infos +41 62 721 73 24</h6>
    130. )
    131. )
    132. [type] =&gt; horizontal
    133. [uid] =&gt;
    134. )
    135. )
    136. [2] =&gt; Array
    137. (
    138. [type] =&gt; quick_form
    139. [size] =&gt; 1/1
    140. [fields] =&gt; Array
    141. (
    142. [title] =&gt; Bestellnummer +41 62 721 73 24 oder füllen Sie unten stehendes Formular aus. Wir Rufen Sie an!
    143. [form] =&gt; [contact-form-7 id="9796" title="CallBack Contact Form"]
    144. )
    145. )
    146. )
    147. )
    148. )
    Alles anzeigen


    ab [type] =&gt; tabs klapt es nicht mehr
  • par0noid schrieb:

    Hey,

    also ich weiß nicht ob ich für alle spreche die dieses Thema bereits gelesen haben, aber mich schreckt ab das du so viel Code gepostet hast.


    ^^ Ja stimme ich mal zu.

    Ich sehe hier nur 2 HTML Ausgaben. Was das Problem ist, kann man leider nicht erkennen.
    Vielleicht musst du ein wenig ins Detail gehen, damit wir dir helfen können.
    Lerne nicht Programmiersprachen, lerne Programmieren...

    :D Alles andere ist Syntax :D

    [Blockierte Grafik: http://www.xing.com/img/buttons/10_en_btn.gif]